numerical solution of equation

syms m_c_theta1 m_c0 M theta1 j_L0 j_L_theta1 l
syms m_c_gama k1 gama j_L_gama
j_L_theta1=1.5;
theta1=120;
k1=0.423;
gama=180;
m_c_gama=0.9;
j_L_gama=0.3;
l=0.218;
eqn1=m_c_theta1==(m_c0-1/M+1)*cos(theta1)+j_L0*sin(theta1)+1/M-1;
eqn2=j_L_theta1==(-m_c0+1/M-1)*sin(theta1)+j_L0*cos(theta1);
%eqn3=m_m_theta1==1;
%eqn3=j_Lm_theta1==j_Lm0+l*theta1;
%eqn4=m_c_theta2==j_L_theta1*sin(theta2-theta1)+(m_c_theta1+1)*cos(theta2-theta1)-1;
%eqn5=j_L_theta2==j_L_theta1*cos(theta2-theta1)-(m_c_theta1+1)*sin(theta2-theta1);
%m_m_theta2=1;
%qn6=j_Lm_theta2==j_Lm0+l*theta2;
eqn7=m_c_gama==(1/k1)*j_L_theta1*sin(k1*((gama-theta1)*(pi/180))*(180/pi))+m_c_theta1*cos(k1*((gama-theta1)*(pi/180))*(180/pi));
eqn8=j_L_gama==j_L_theta1*cos(k1*((gama-theta1)*(pi/180))*(180/pi))-k1*m_c_theta1*sin(k1*((gama-theta1)*(pi/180))*(180/pi));
%eqn9=j_Lm_gama==j_L_gama;
%m_m_gama=(-m_c_theta2*cos(k1*(gama-theta2))-(1/k1)*j_L_theta2*sin(k1*(gama-theta2)))/(1+l)
m_c_gama=-m_c0;
j_L_gama=-j_L0;
j_L_theta1=(theta1*(pi/180)*l)/2;
j_L_gama=j_L_theta1-l*(gama-theta1)*(pi/180);
%j_L_theta2=j_Lm_theta2;
%j_Lm0=-j_Lm_gama;
%j_L_gama=j_Lm_gama;
eqns = subs([eqn1, eqn2, eqn7, eqn8]);
sol = vpasolve(eqns, m_c0, j_L0, m_c_theta1,M)
Hi all I want solve these equations numerically and I have given all the values required. but it is showing something like that: % m_c0: [0x1 sym] j_L0: [0x1 sym] m_c_theta1: [0x1 sym] M: [0x1 sym]
I am not sure what is the problem. Can anyone help please?

 Accepted Answer

You have
theta1=120;
and
eqn1=m_c_theta1==(m_c0-1/M+1)*cos(theta1)+j_L0*sin(theta1)+1/M-1;
is theta1 in degrees or in radians?
Your expressions are really polluted with pi/180 and 180/pi . You should work entirely in radians and only covert to degrees if the user interface demands it.
If you do convert theta1 from degrees to radians you will still get no solution. Your four equations in eqns are not independent. If you solve the first three for m_c0, j_L0, m_c_theta1 and substitute the results into the last one, the remaining equation is independent of the final variable, M. Instead it has constants expressions on both sides, and the values on the two sides are quite different, one being 3/10 and the other being a value that is close to (but not exactly) pi/2

15 Comments

theta1 and gamma is in degree. as there is a term k1 which is in radian that's why i need to convert it to degree.
sin(k1*(gama-theta2))
Well, change theta1 and gama into radians for the purpose of the computations; it will make the formulas much simpler.
If the user needs to see degrees for some reason, then make the change at the user interface level, not in the formula.
Notice that your code has
j_L_gama = -j_L0;
j_L_theta1 = (theta1*(Pi/180)*l)/2;
j_L_gama = j_L_theta1-l*(gama-theta1)*(Pi/180);
The third of those lines overwrites the result of the first of those lines.
its still giving the empty matrix
You have
m_c_gama=0.9;
and later
m_c_gama=-m_c0;
but in the meantime you have used m_c_gama in
eqn7 = m_c_gama == (1/k1)*j_L_theta1*sin(k1*((gama-theta1)*(Pi/180))*(180/Pi))+m_c_theta1*cos(k1*((gama-theta1)*(Pi/180))*(180/Pi));
When you overwrite it with -m_c0 later, that introduces a contradiction.
You also have
j_L_gama=0.3;
then
eqn8=j_L_gama==j_L_theta1*cos(k1*((gama-theta1)*(pi/180))*(180/pi))-k1*m_c_theta1*sin(k1*((gama-theta1)*(pi/180))*(180/pi));
and then overwrite j_L_gama later. That also introduces a contradiction.
safi58
safi58 on 20 Feb 2017
Edited: safi58 on 20 Feb 2017
if true
% syms m_c0 j_L0 theta1 M m_c_gama j_L_gama j_L_theta1
syms m_c_theta1 gama l
% m_c0=-1.2;
% j_L0=-1.5;
% theta1=10;
% M=0.84;
m_c_theta1=-1.5;
j_L_theta1=-0.6;
m_c_gama=1.2;
j_L_gama=1.6;
gama=180;
eqn1 = m_c_theta1==(m_c0-1/M-1)*cos(theta1)+j_L0*sin(theta1)+1/M+1;
eqn2 = j_L_theta1==(-m_c0+1/M+1)*sin(theta1)+j_L0*cos(theta1);
eqn3 = m_c_gama==(m_c_theta1-1/M+1)*cos(gama-theta1)+j_L_theta1*sin(gama-theta1)+1/M-1
eqn4 = j_L_gama==(-m_c_theta1+1/M-1)*sin(gama-theta1)+j_L_theta1*cos(gama-theta1);
m_c_gama=-m_c0;
j_L_gama=-j_L0;
j_L_theta1=-(gama*(pi/180)*l)/2;
eqns = subs([eqn1, eqn2, eqn3, eqn4]);
sol = vpasolve(eqns, m_c0, j_L0, theta1,M)
m_c0=3.1107110219989128985169431569636;
j_L0=-3.7080970006952523526652648628545;
theta1=39.33774189248118490192583849302;
M=0.7952871870397643593519882179676;
eqn=subs([eqn1, eqn2, eqn3, eqn4]);
solq=vpa(eqn)
I have run this code which is working fine but I am not sure why that code is not working
I have actually found the symbolic solution and i am just trying to validate it numerically.
do you have any suggestion?
You assign m_c_gama 1.2 before eqn3 and assign it something else after eqn4 . That is a contradiction that cannot be resolved.
Thanks Walter.
Hi Walter,
syms m_c_theta1 m_c0 M theta1 j_L0 j_L_theta1 l
syms m_c_theta2 theta2 j_L_theta2 m_c_gama k1 gama j_L_gama
%theta1=1.13;
theta2=0.79;
k1=0.423;
gama=2.992;
M=0.575;
j_L_theta2=0.295;
eqn1=m_c_theta1==(m_c0-1/M+1)*cos(theta1)+j_L0*sin(theta1)+1/M-1;
eqn2=j_L_theta1==(-m_c0+1/M-1)*sin(theta1)+j_L0*cos(theta1);
%eqn3=m_m_theta1==1;
%eqn3=j_Lm_theta1==j_Lm0+l*theta1;
eqn4=m_c_theta2==j_L_theta1*sin(theta2-theta1)+(m_c_theta1+1)*cos(theta2-theta1)-1;
eqn5=j_L_theta2==j_L_theta1*cos(theta2-theta1)-(m_c_theta1+1)*sin(theta2-theta1);
%m_m_theta2=1;
%qn6=j_Lm_theta2==j_Lm0+l*theta2;
eqn7=m_c_gama==(1/k1)*j_L_theta2*sin(k1*(gama-theta2))+m_c_theta2*cos(k1*(gama-theta2));
eqn8=j_L_gama==j_L_theta2*cos(k1*(gama-theta2))-k1*m_c_theta2*sin(k1*(gama-theta2));
%eqn9=j_Lm_gama==j_L_gama;
%m_m_gama=(-m_c_theta2*cos(k1*(gama-theta2))-(1/k1)*j_L_theta2*sin(k1*(gama-theta2)))/(1+l)
m_c_gama=1.06;
j_L_gama=0.196;
m_c_gama=-m_c0;
j_L_gama=-j_L0;
j_L_theta2=(theta2*l)/2;
%j_L_gama=j_L_theta2-l*(gama-theta2);
%j_L0=-(l*theta2)/2;
%j_L_theta2=j_Lm_theta2;
%j_Lm0=-j_Lm_gama;
%j_L_gama=j_Lm_gama;
eqns = subs([eqn1, eqn2, eqn4, eqn5, eqn7, eqn8]);
sol = vpasolve(eqns, m_c0, j_L0, m_c_theta1,j_L_theta1,m_c_theta2,theta1)
m_c0=-0.39289591378964274585530032992682;
j_L0=-0.27088696263626641953863259616783;
j_L_theta1=0.421956688825526733574708738748;
m_c_theta1=-0.34568104798456967041840352345195;
m_c_theta2=-0.27947537293221308274025724123993;
theta1=0.60583699309915328562813545298189;
eqn = subs([eqn1, eqn2, eqn4, eqn5, eqn7, eqn8]);
solq=vpa(eqn)
I have tried this one but m_c_gama should equal to m_c_o and j_L_gama should equal to j_L_0? Do you have any suggestion?
After solving the symbolic equations sol I will get m_c0, j_L0, m_c_theta1,j_L_theta1,m_c_theta2,theta1. But when I put the values I am geeting imaginary values. I have posted it another link. I am giving it here. https://au.mathworks.com/matlabcentral/answers/329492-why-am-i-getting-imaginary-values
How can m_c_gama be equal to m_c_o when you have
m_c_gama=-m_c0;
A value cannot equal its own negative unless the value is 0.
Sorry for that. what I meant to say that if m_c0=-.138, then m_c_gama should be 0.138
I am not sure what the question is at this point? With your most recent code, the output of solq is a series of equations are true to within round-off error of the sort that would be expected with back-substitution.
I have declared m_c_gama=1.06 and m_c0 should be -1.06 rather I am getting -0.39
Your code has
m_c_gama=Q(1.06);
j_L_gama=Q(0.196);
m_c_gama=-m_c0;
Notice you overwrite m_c_gama. Later you have
m_c0=Q(-0.39289591378964274585530032992682);
so that is where the 0.39* is coming from.

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 20 Feb 2017
I recall an old phrase: "If wishes were horses, then beggars would ride."
Just wanting a solution to a set of nonlinear equations to exist does not make that so. Not all such systems of equations must have a solution. MATLAB has told you that no solution was found, although that does not ensure none exists.

2 Comments

I am getting the solution symbolically but when I am trying to do numerically it is returning empty matrix.
The empty matrix indicated that no solution existed.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!