Solve Function returning empy values?

I can't figure out why the values returned for each variable is empty. I have 5 equations and 5 unkowns. Where am i going wrong?

 Accepted Answer

  1. We cannot copy and paste code from images of the code in order to test it.
  2. It is a categorical error to use solve() in any equation that containst floating point coefficients. solve() is for finding exact solutions, but floating point numbers are never exact. You want an exact solution, but the gravity you used is not exact: standard g is 9.80665, and g on Earth is measured to be between 9.76392 m/s^2 and 9.83366 m/s^2 https://agupubs.onlinelibrary.wiley.com/doi/full/10.1002/grl.50838 . Exactly where on Earth you are making the calculation for will make a difference to the exact answer -- and exact answers are the only ones you should be using solve() for.
  3. If your parameters are only approximate, you should be using the approximate solver, vpasolve()

3 Comments

OK I understand know that use of vpasolve is required. However when I use the exact same equations in vpasolve vs. the equationsToMatrix function, I get completely different answers. Code attatched this time.
clc
clear
syms c x y p s
l = .45; %length on tibia/fibula in m
theta = 70; %in deg
phi = 15; %in deg
w = (3770/2)+(9.81*(.87*(120/2))); %weight in newton
f_l = 9.81*.13*(120/2); %force of the lower leg in newtin
vars = [c x y p s];
eqns = [-c+cosd(theta)*x+y*sind(theta)-f_l*sind(theta)-w*sind(theta)+p*cosd(phi) == 0, %sum of forces in r
-s+p*sind(phi)-w*cosd(theta)-f_l*cosd(theta)-sind(theta)*x+y*cosd(theta) == 0, %sum of forces in theta
-(l/2)*f_l*cosd(theta)-l*w*cosd(theta)-l*s+p*sind(phi) == 0, %moment on ankle
(l/2)*x*sind(theta)-(l/2)*y*cosd(theta)-(l/2)*w*cosd(theta)-s*(l/2)+(l/2)*p*sind(phi) == 0, %moment on knee
-l*y*cosd(theta)+l*x*sind(theta)+(l/2)*f_l*cosd(theta) == 0]; %moment on knee
[A,B] = equationsToMatrix(eqns,vars);
Answer = round(B)
clc
clear
syms c x y p s
l = .45; %length on tibia/fibula in m
theta = 70; %in deg
phi = 15; %in deg
w = (3770/2)+(9.81*(.87*(120/2))); %weight in newton
f_l = 9.81*.13*(120/2); %force of the lower leg in newtin
eqn1 = -c+cosd(theta)*x+y*sind(theta)-f_l*sind(theta)-w*sind(theta)+p*cosd(phi) == 0; %sum of forces in r
eqn2 = -s+p*sind(phi)-w*cosd(theta)-f_l*cosd(theta)-sind(theta)*x+y*cosd(theta) == 0; %sum of forces in theta
eqn3 = -(l/2)*f_l*cosd(theta)-l*w*cosd(theta)-l*s+p*sind(phi) == 0; %moment on ankle
eqn4 = (l/2)*x*sind(theta)-(l/2)*y*cosd(theta)-(l/2)*w*cosd(theta)-s*(l/2)+(l/2)*p*sind(phi) == 0; %moment on knee
eqn5 = -l*y*cosd(theta)+l*x*sind(theta)+(l/2)*f_l*cosd(theta) == 0; %moment on knee
sol = vpasolve([eqn1, eqn2, eqn3, eqn4, eqn5],[c x y p s]);
c = round(sol.c)
x = round(sol.x)
y = round(sol.y)
p = round(sol.p)
s = round(sol.s)
You should not be taking B as your solution: you should be looking at A\B as your solution.
You will find that it is all infinities. That is because your equations are inconsistent.
If you solve the first equation for c and substitute that into the rest, and then solve the (new) second equation for x and substitute that into the rest, then you will find that y has disappeared. There is a dependence between c and x and y.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!