Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/Questions/How to fix "solve() throws this result empty sym: 0-by-1 and fails to get the correct results"?
Next
Answered
Charles Walsh
  • 7
Charles Walsh
Asked: May 18, 20222022-05-18T19:00:16+00:00 2022-05-18T19:00:16+00:00In: matlab

How to fix “solve() throws this result empty sym: 0-by-1 and fails to get the correct results”?

  • 7

How to fix “solve() throws this result Empty sym: 0-by-1 and fails to get the correct results”? Here is the code that I run:

syms v1 v2 v3
 eqns = [5*v1 -2*v2 -3*v3 == 24, ...
  4*v1 +5*v2 == 0, ...
  -6*v1 +12*v2 +8*v3 == 0];
 vars = [v1 v2 v3];
 answer = solve(eqns,vars);
 vpa(answer.v1)
 vpa(answer.v2)
 vpa(answer.v3)
ans =
 Empty sym: 0-by-1
 ans =
 Empty sym: 0-by-1
 ans =
 Empty sym: 0-by-1
syms v1 v2 v3
 eqn1 = 5*v1 -2*v2 -3*v3 == 24;
 eqn2 = 4*v1 +5*v2 == 0;
 eqn3 = -6*v1 +12*v2 +8*v3 == 0;
 eqns = [eqn1,eqn2,eqn3];
 vars = [v1 v2 v3];
 answer = solve(eqns, vars);
 vpa(answer.v1)
 vpa(answer.v2)
 vpa(answer.v3)
ans =
 32.0
 ans =
 -25.6
 ans =
 62.4

Can someone share with me your knowledge and experience?

  • 2 2 Answers
  • 284 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-27T14:50:01+00:00Added an answer on June 27, 2022 at 2:50 pm

    The cause:

    The reason of this error is from the following line:

    eqns = [5*v1 -2*v2 -3*v3 == 24, ...
    4*v1 +5*v2 == 0, ...
    -6*v1 +12*v2 +8*v3 == 0];

    If you run this line and write equations in the console, you will receive:

    >> eqns
    eqns =
    [ 5*v1, -2*v2, -3*v3 == 24, 4*v1, 5*v2 == 0, -6*v1, 12*v2, 8*v3 == 0]

    It says that there are actually 8 equations, not 3 equations. This is the reason why you don’t find any answers and the error happens.

    Solution:

    To solve this error, you need to add several spaces. It seems that the sequence space->plus or minus sign->digit is interpreted as a new equation, which is a bizarre behavior. As a consequence, the program:

    syms v1 v2 v3
    eqns = [5*v1 - 2*v2 - 3*v3 == 24,...
    4*v1 + 5*v2 == 0,...
    -6*v1 + 12*v2 + 8*v3 == 0];
    vars = [v1 v2 v3];
    answer = solve(eqns);
    vpa(answer.v1)
    vpa(answer.v2)
    vpa(answer.v3)

    will give the accurate answer as below:

    ans =
    32.0
    ans =
    -25.6
    ans =
    62.4
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Mia Claude
    2022-05-25T20:50:00+00:00Added an answer on May 25, 2022 at 8:50 pm

    Line is the problem

    eqns = [5*v1 -2*v2 -3*v3 == 24, ...
     4*v1 +5*v2 == 0, ...
     -6*v1 +12*v2 +8*v3 == 0];

    This line can be executed and then entered eqns into console to get:

    >> eqns
    eqns =
    [ 5*v1, -2*v2, -3*v3 == 24, 4*v1, 5*v2 == 0, -6*v1, 12*v2, 8*v3 == 0]

    This is 8 equations rather than 3. This is why there is no solution. If you add spaces, the problem disappears. Strange behavior. It appears that the sequence space->plus/minus sign->digit can be understood as a new equation. Hence,

    syms v1 v2 v3
    eqns = [5*v1 - 2*v2 - 3*v3 == 24,...
     4*v1 + 5*v2 == 0,...
     -6*v1 + 12*v2 + 8*v3 == 0];
    vars = [v1 v2 v3];
    answer = solve(eqns);
    vpa(answer.v1)
    vpa(answer.v2)
    vpa(answer.v3)

    The correct answer will be returned:

    ans =
    32.0
    ans =
    -25.6
    ans =
    62.4
    • 16
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.