How to use Fsolve with multiple variables

Hi. I am trying to solve two non-linear equations using fsolve. Here are my two codes:
-------------
function G=Teth3(x,p,H,L);
g=9.82;
mu=0.0141*g;
G=[H-(x(2)/mu).*(cosh(mu.*(x(1)+p)/x(2))-cosh(mu.*x(1)/x(2))); %function G defines a vector of two functions to be solved
L-(x(2)/mu).*(sinh(mu.*(x(1)+p)/x(2))-sinh(mu.*x(1)/x(2)))];
end
-------------
function F = tethsolve3(p,H,L);
x0=[2;2];
g=9.82;
mu=0.0141*g;
[x,fval]=fsolve(@Teth3,x0,p,H,L);
end
-------------
I want the second one (tethsolve3) to get three inputs p, H, L (which will be used as constants) and solve the first function (Teth3) which is a function of x(vector of 2 variables) and p,H,L. I don't know what format I should use for the Fsolve. Please advise. Thank you very much.

2 comentarios

LAKKIMSETTI SUNANDA
LAKKIMSETTI SUNANDA el 1 de Feb. de 2021
Hi. I also have a problem in solving the equations. I have four equations and four unknowns and I have to find those 4 unknown variables. The equations are as follows:
2*Y1*tan(t1_1)+Y2*tan(t2_1)+Y3*tan(t3_1)==0;
2*Y1*tan(t1_3)+Y2*tan(t2_3)+Y3*tan(t3_3)==0;
b1== (t1_1*Y1)+(t2_1*(Y2/2)*((sec(t2_1)^2)/(sec(t1_1)^2)))+(t3_1*(Y3/2)*((sec(t3_1)^2)/(sec(t1_1)^2)));
b3== (t1_3*Y1)+(t2_3*(Y2/2)*((sec(t2_3)^2)/(sec(t1_3)^2)))+(t3_3*(Y3/2)*((sec(t3_3)^2)/(sec(t1_3)^2)));
Here Y1,b1,b3 are known values and the unknown variables are Y2,Y3,l2,l3. The above t1,t2,t3 are in terms of l2 and l3.
t2_1=(2*pi/lambda(1))*l2;
t3_1=(2*pi/lambda(1))*l3;
t2_3=(2*pi/lambda(3))*l2;
t3_3=(2*pi/lambda(3))*l3;
t1_1=(2*pi/lambda(1))*l1;
t1_3=(2*pi/lambda(3))*l1;
Please help me with this. Thank you.
Alan Weiss
Alan Weiss el 21 de En. de 2022
I suggest that you ask your question in a new topic rather than reopening an old topic.
That said, have you tried the Problem-Based Workflow for Solving Equations? It is a very natural way of solving equations.
Alan Weiss
MATLAB mathematical toolbox documentation

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Oct. de 2013
[x,fval] = fsolve(@(x) Teth3(x, P, H, L), x0);

23 comentarios

Sina
Sina el 22 de Oct. de 2013
Thanks a lot Walter. It worked perfectly.
Sina.
fredo ferdian
fredo ferdian el 13 de Jun. de 2016
Editada: fredo ferdian el 13 de Jun. de 2016
Hi! I work in typical problem, few nonlinear equations with few unknowns. But even for this script (which seems to be already works perfectly), i still can't used it. So, how to run these script ?
This is what i tried to do
1. Save the Teth3 function with Teth3 name as one file .m
2. Save the tethsolve3 function in separate file as .m with tethsolve3 name
3. type [x,fval] = fsolve(@(x) Teth3(x, P, H, L), x0); in command window
then this following error occur:
Undefined function or variable 'x0'.
Sorry, but could you write down the step to run this script please? Because I have similar error with my script
Thanks in advance
Walter Roberson
Walter Roberson el 13 de Jun. de 2016
Do not call fsolve from the command window: run tethsolve3 instead, as it defines x0
safi58
safi58 el 16 de Nov. de 2016
Editada: Walter Roberson el 16 de Nov. de 2016
Hi,
function G=Teth3(x,p,H,L);
g=9.82;
mu=0.0141*g;
G=[H-(x(2)/mu).*(cosh(mu.*(x(1)+p)/x(2))-cosh(mu.*x(1)/x(2))); %function G defines a vector of two functions to be solved
L-(x(2)/mu).*(sinh(mu.*(x(1)+p)/x(2))-sinh(mu.*x(1)/x(2)))];
x0=[2;2]
[x,fval] = fsolve(@(x) Teth3(x, P, H, L), x0);
I have run this code but anerror occurs showing '' not enough input arguments. Can you please help me?
You need to break that into multiple routines.
function x = tethsolve3(p,H,L);
x0=[2;2];
[x,fval] = fsolve(@(x) Teth3(x, P, H, L), x0);
and
function G=Teth3(x,p,H,L);
g=9.82;
mu=0.0141*g;
G=[H-(x(2)/mu).*(cosh(mu.*(x(1)+p)/x(2))-cosh(mu.*x(1)/x(2))); %function G defines a vector of two functions to be solved
L-(x(2)/mu).*(sinh(mu.*(x(1)+p)/x(2))-sinh(mu.*x(1)/x(2)))];
Now, go to the command line and define some values, like
P = 3.8;
H = -4.934;
L = sqrt(2);
and then command
tethsolve3(P, H, L)
safi58
safi58 el 17 de Nov. de 2016
Editada: safi58 el 17 de Nov. de 2016
Thank you so much for your response. If I want to gave the function G in terms of P,H,L without giving constant value, how would I do that?
function x = tethsolve3(p, H, L);
g=9.82;
mu=0.0141*g;
x0=[2;2];
[x,fval] = fsolve(@(x) Teth3(x, P, H, L, mu), x0);
function G=Teth3(x, p, H, L, mu);
G=[ H-(x(2)/mu).*(cosh(mu.*(x(1)+p)/x(2))-cosh(mu.*x(1)/x(2)));
L-(x(2)/mu).*(sinh(mu.*(x(1)+p)/x(2))-sinh(mu.*x(1)/x(2)))];
safi58
safi58 el 18 de Nov. de 2016
Thanks.
I am trying to run this code but it is showing not enough input arguments.
I am not quite sure what is going on?
You need to go to the command line and request to run tethsolve3() and pass in values for p, H, and L, like I showed above
P = 3.8; %for example
H = -4.934;
L = sqrt(2);
tethsolve3(p, H, L)
If you prefer you could build the appropriate values into tethsolve3:
function x = tethsolve3
P = 3.8; %for example
H = -4.934;
L = sqrt(2);
g=9.82;
mu=0.0141*g;
x0=[2;2];
[x,fval] = fsolve(@(x) Teth3(x, P, H, L, mu), x0);
safi58
safi58 el 18 de Nov. de 2016
But I need the value of x in terms of p,H, L without declaring them such as x=p^2+H+L for example
That cannot be determined using fsolve(). You would need the Symbolic toolbox to get started.
There is no closed form solution for your x values. The values can be expressed in non-linear terms as formulae involving a quantity which for the moment I will call R.
R = RootOf( H^2 * Z^2 * exp(Z) - L^2 * Z^2 * exp(Z) + p^2 * (exp(Z))^2 - 2 * p^2 * exp(Z) + p^2, Z)
That is, R is the set of value, Z, such that the expression inside the RootOf() becomes 0. There is no closed form solution for that expression. There may be multiple solutions, especially complex-valued. 0 is a solution, but in the overall expression that leads to division by 0, so it is not a correct solution to the overall equations.
Once you have a value for R, then
x(1) = -R*exp(R)*p*(H-L)*(H+L)*(exp(R)-1)*(R-ln(-p*(exp(R)-1)/(R*(H-L))))/(((H^2-L^2)*R^2+p^2)*(exp(R))^2-2*exp(R)*p^2+p^2)
x(2) = (H-L)*exp(R)*R*(H+L)*mu*p*(exp(R)-1)/(((H^2-L^2)*R^2+p^2)*(exp(R))^2-2*exp(R)*p^2+p^2)
which is not pretty but at least can be simply mechanically applied once you have an R.
With the values I randomly selected for p, H, L above, the solutions to R are all imaginary (except for R = 0, a false solution.)
safi58
safi58 el 18 de Nov. de 2016
Editada: Walter Roberson el 18 de Nov. de 2016
Thank you for your effort.
Actullay my original equations are
F(1) = x(1)+[[x(1)-x(4)+1]*cos(x(3))+x(2)*sin(x(3))-1]*cos(k(m-x(3)))+[[-x(1)+(1/x(4))-1]*sin(x(3))+x(2)*cos((3))]*sin(k(m-x(3)))/k+(1/x(4));
F(2) = x(2)+[-[x(1)-(1/x(4)+1)]*cos(x(3))-x(2)*sin(x(3))+1]*k*sin(k(m-x(3)))+[-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3));
F(3)= [-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3))-x(2)-n*m;
F(4)= [[-x(1)+1/x(4)-1]*(1-cos(x(3)))+x(2)*sin(x(3))-x(2)*x(3)+(n*x(3)^2)/2]*((pri^2*R)/m*sec^2*Z);
where I have to find the values of x1,x2,x3,x4 in terms of n,m,k,R,pri,sec.
Can you please help me with this?
Walter Roberson
Walter Roberson el 18 de Nov. de 2016
If you need a closed form solution, then solve F(1) for x(1), substitute that result into F(2), F(3), F(4). Solve the new F(2) for x(2), substitute that result into the new F(3), F(4). Solve the new new F(4) for x(4) . You will get two solutions. Substitute one of them into the new new F(3) . You now have F(3) = a moderately long equation in x(3) and the other variables.
From there you could try to solve that F(3) for x(3) but I think it highly unlikely you will succeed symbolically.
I do not think you will be able to get any further than this symbolically. To get any further you would need to give specific values for F(1), F(2), F(3), F(4), n, m, k, R, pri, sec, and Z, after which you could vpasolve()
safi58
safi58 el 18 de Nov. de 2016
Editada: Walter Roberson el 18 de Nov. de 2016
oh sorry!!!!!!
0 = x(1)+[[x(1)-x(4)+1]*cos(x(3))+x(2)*sin(x(3))-1]*cos(k(m-x(3)))+[[-x(1)+(1/x(4))-1]*sin(x(3))+x(2)*cos((3))]*sin(k(m-x(3)))/k+(1/x(4));
0 = x(2)+[-[x(1)-(1/x(4)+1)]*cos(x(3))-x(2)*sin(x(3))+1]*k*sin(k(m-x(3)))+[-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3));
0= [-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3))-x(2)-nm;
0= [[-x(1)+1/x(4)-1]*(1-cos(x(3)))+x(2)*sin(x(3))-x(2)*x(3)+(n*x(3)^2)/2]*((pri^2*R)/m*sec^2*Z);
The equations would be like this.
These equations have been solve in Matlab using fsolve in a paper they claim but I am unable to program it.
I think you a expert in MATLAb. can you please help in any way?
Walter Roberson
Walter Roberson el 18 de Nov. de 2016
You get to the point
0 = 2*(((1/4)*(-(1/2)*sin(x3)^2*m*n+(cos(x3)+1/2)*(cos(x3)-cos(3)-1)*sin(x3)-(1/2)*m*n*cos(3)*cos(x3))*k^2*(x3*sin(x3)^2+cos(x3)*sin(x3)-x3)*sin(k(m-x3))^5-(1/4)*(-(1/2)*sin(x3)^4*k^2*x3+((-(1/2)*k^2-m*n*x3)*cos(x3)-(1/2)*m*n*x3*(k^2-cos(3)+1))*sin(x3)^3+(x3*cos(x3)^2+(-(1/2)*x3+(1/2)*k^2*x3-(1/2)*n*m-x3*cos(3))*cos(x3)+(-(1/2)*x3+(1/2)*n*m)*cos(3)-(1/2)*x3-(1/2)*k^2*m*n-
and so on, extending to 52000 characters.
You are never going to find a closed-form solution for that.
If you had specific n, m, k, R, pri, sec, and Z values, then substitute them into your original equations and vpasolve() to get one of the solutions, provided you have the symbolic toolbox.
safi58
safi58 el 21 de Nov. de 2016
Hi Walter,these equations do not have closed form solution.I just need to solve these numerically.
Walter Roberson
Walter Roberson el 21 de Nov. de 2016
Assign specific numeric values for n, m, k, R, pri, sec, and Z when creating your equations, and vpasolve() the equations to be given some solution.
safi58
safi58 el 21 de Nov. de 2016
I cannt give specific values and that's the problem. Is it possible to find the solution of these equations in terms of n, m, k, R, pri, sec, and Z without giving their specific value?
Walter Roberson
Walter Roberson el 21 de Nov. de 2016
You are contradicting yourself. You are saying "I just need to solve these numerically" but you are saying that you want the equations in terms of the symbols, which is a symbolic solution rather than a numeric solution.
The equation is much too complex in sin() and cos() and x3 to hope for a closed form symbolic solution.
If, somehow, I could give you a formula for x(1), x(2), x(3), x(4) in terms of the symbols n, m, k, R, pri, sec, and Z, then what would you do what those formulae?
A code outline is
syms n m k R pri sec Z
x = sym('x', [1 4]);
eqn = [x(1)+[[x(1)-x(4)+1]*cos(x(3))+x(2)*sin(x(3))-1]*cos(k*(m-x(3)))+[[-x(1)+(1/x(4))-1]*sin(x(3))+x(2)*cos((3))]*sin(k*(m-x(3)))/k+(1/x(4));
x(2)+[-[x(1)-(1/x(4)+1)]*cos(x(3))-x(2)*sin(x(3))+1]*k*sin(k*(m-x(3)))+[-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3));
[-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3))-x(2)-n*m;
[[-x(1)+1/x(4)-1]*(1-cos(x(3)))+x(2)*sin(x(3))-x(2)*x(3)+(n*x(3)^2)/2]*((pri^2*R)/m*sec^2*Z)];
X1 = solve(eqn(1), x(1));
eqn234 = subs(eqn(2:end), x(1), X1);
X2 = solve(eqn234(1), x(2));
eqn34 = subs(eqn234(2:end),x(2), X2);
X4 = solve(eqn34(2), x(4));
eqn3_1 = subs(eqn34(1), x(4), X4(1));
X3_1 = solve(eqn3_1, x(3));
eqn3_2 = subs(eqn34(1), x(4), X4(2));
X3_2 = solve(eqn3_2, x(3));
You will be able to get as far as X1, X2, X4, but the X3_* are hopeless symbolically.
safi58
safi58 el 21 de Nov. de 2016
Walter you are a legend. Thank you very much. Can I have your contact details please?
Walter Roberson
Walter Roberson el 21 de Nov. de 2016
You can send messages through my profile.
Alek Yawfimetz
Alek Yawfimetz el 18 de Abr. de 2020
I appreciate the help Walter, I had a similar issue and this helped me solve it instantly. Thanks.

Iniciar sesión para comentar.

Más respuestas (4)

Manuela Gräfe
Manuela Gräfe el 24 de Abr. de 2017

1 voto

Hello umme mumtahina,
please send me an personal message. I am also interested in the solutions of your questions.
Sometimes you just write: "Got it!", but you don't give the final solution. Due to the fact, that this is a public community, you should provide the corresponding answers to your questions.
So please send me ASAP a personal message.
safi58
safi58 el 21 de Nov. de 2016

0 votos

in this paper on page 3284, they have used fsolve to solve those equations. see upper right side.

10 comentarios

fsolve() is completely numeric and so would require that you had specific numeric values for all of the symbols.
The fsolve version of your code would be to first give numeric values to everything except x and then define
f = @(x) [x(1)+[[x(1)-x(4)+1]*cos(x(3))+x(2)*sin(x(3))-1]*cos(k*(m-x(3)))+[[-x(1)+(1/x(4))-1]*sin(x(3))+x(2)*cos((3))]*sin(k*(m-x(3)))/k+(1/x(4));
x(2)+[-[x(1)-(1/x(4)+1)]*cos(x(3))-x(2)*sin(x(3))+1]*k*sin(k*(m-x(3)))+[-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3));
[-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3))-x(2)-n*m;
[[-x(1)+1/x(4)-1]*(1-cos(x(3)))+x(2)*sin(x(3))-x(2)*x(3)+(n*x(3)^2)/2]*((pri^2*R)/m*sec^2*Z)];
guess = rand(1,4); %or some other starting value
X = fsolve(f, guess);
safi58
safi58 el 1 de Dic. de 2016
Editada: Walter Roberson el 1 de Dic. de 2016
k=0.423;
m=180;
n=0.218;
pri=6;
sec=80;
Z=1.36;R=533.33;
f = @(x) [x(1)+[[x(1)-x(4)+1]*cos(x(3))+x(2)*sin(x(3))-1]*cos(k*(m-x(3)))+[[-x(1)+(1/x(4))-1]*sin(x(3))+x(2)*cos((3))]*sin(k*(m-x(3)))/k+(1/x(4));
x(2)+[-[x(1)-(1/x(4)+1)]*cos(x(3))-x(2)*sin(x(3))+1]*k*sin(k*(m-x(3)))+[-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3));
[-x(1)+1/x(4)-1]*sin(x(3))+x(2)*cos(x(3))-x(2)-n*m;
[[-x(1)+1/x(4)-1]*(1-cos(x(3)))+x(2)*sin(x(3))-x(2)*x(3)+(n*x(3)^2)/2]*((pri^2*R)/m*sec^2*Z)];
x0 = [-1 -1 -1 -1]; %or some other starting value
X = fsolve(f, x0);
Hi Walter,
I have run this code but it is showing
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 400 (the default value).
What should I do now?
options = optimoptions(@fsolve, 'MaxFunEvals', 1000);
X = fsolve(f, x0, options);
safi58
safi58 el 1 de Dic. de 2016
its still not working
Walter Roberson
Walter Roberson el 1 de Dic. de 2016
If it stopped again saying it was stopping prematurely because of the function evaluation limit and listed the new value that you set, then try again with an even larger value.
If it gave any other message instead please show that message.
safi58
safi58 el 1 de Dic. de 2016
I tried with this
options = optimoptions(@fsolve, 'MaxFunEvals',2000);
it is showing
Solver stopped prematurely.
fsolve stopped because it exceeded the iteration limit, options.MaxIter = 400 (the default value).
options = optimoptions(@fsolve, 'MaxFunEvals', 1000000, 'MaxIter', 1000000);
safi58
safi58 el 4 de Dic. de 2016
Editada: Walter Roberson el 5 de Dic. de 2016
Hi Walter,
Sorry to disturb you again and again.
But I am still having problem.
I have done some changes in equations.
Can you please tell me what should be done now?
f =@(x) [x(1)+[[x(1)-(1/x(4))+1]*cos(x(3))+x(2)*sin(x(3))-1]*cos(k*(m-x(3)))+(1/k)*[[-x(1)+(1/x(4))-1]*sin(x(3))+x(2)*cos(x(3))]*sin(k*(m-x(3)))+(1/x(4));
x(2)+[[-x(1)+(1/x(4))-1]*xos(x(3))-x(2)*sin(x(3))+1]*k*sin(k*(m-x(3)))+[[-x(1)+(1/x(4))-1]*sin(x(3))+x(2)*cos(x(3))]*cos(k*(m-x(3)));
[-x(1)+(1/x(4))-1]*sin(x(3))+x(2)*cos(x(3))-x(2)-n*x(3);
[[[-x(1)+1/x(4)-1]*(1-cos(x(3)))+x(2)*sin(x(3))-x(2)*x(3)+(n*x(3)^2)/2]*((pri^2*R)/m*sec^2*Z)]-1];
for these equations it is showing
Undefined function 'xos' for input arguments of type 'double'.
Error in dcmb (line 10)
f =
[x(1)+[[x(1)-(1/x(4))+1]*cos(x(3))+x(2)*sin(x(3))-1]*cos(k*(m-x(3)))+(1/k)*[[-x(1)+(1/x(4))-1]*sin(x(3))+x(2)*cos(x(3))]*sin(k*(m-x(3)))+(1/x(4));
Error in fsolve (line 217)
fuser = feval(funfcn{3},x,varargin{:});
Error in dcmb_driver (line 4)
X = fsolve(@dcmb, x0, optimset('MaxFunEvals',2000,'MaxIter',2000));
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
safi58
safi58 el 5 de Dic. de 2016
solved it!!!!!!!!
Manuela Gräfe
Manuela Gräfe el 24 de Abr. de 2017
Hello umme mumtahina,
please send me an personal message. I am also interested in the solutions of your questions.
Sometimes you just write: "Got it!", but you don't give the final solution. Due to the fact, that this is a public community, you should provide the corresponding answers to your questions.
So please send me ASAP a personal message.

Iniciar sesión para comentar.

safi58
safi58 el 6 de Dic. de 2016

0 votos

Hi Walter, after solving these equations i have found the initial condition. Can you please tell me how to draw these waveforms? see page 3247
GUANGHE HUO
GUANGHE HUO el 21 de En. de 2022
Editada: Walter Roberson el 21 de En. de 2022
for i=1:1:position
global alpha_tspd alpha_trpd beta_d R_pd R_sd Rb_sd T_in
K_sp1=K_mesh_sp(i,1);
K_sp2=K_mesh_sp(i,2);
K_sp3=K_mesh_sp(i,3);
K_rp1=K_mesh_rp(i,1);
K_rp2=K_mesh_rp(i,2);
K_rp3=K_mesh_sp(i,3);
theta_s=Theta_s(i,1);
F=@(x)[ (K_sp1*x(1)*cos(alpha_tspd)-K_rp1*x(4)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp2*x(2)*cos(alpha_tspd)-K_rp2*x(5)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp3*x(3)*cos(alpha_tspd)-K_rp3*x(6)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp1*x(1)+K_sp2*x(2)+K_sp3*x(3))*cos(beta_d)*cos(alpha_tspd)*R_sd-T_in;
x(4)-theta_s*Rb_sd-x(1);
x(5)-theta_s*Rb_sd-x(2);
x(6)-theta_s*Rb_sd-x(3) ];
x0=delta(i,:);
options=optimoptions('fsolve','Algorithm','levenberg-marquardt');
delta(i+1,:)=fsolve(F,x0,options);
end
Hi, above are my code, every time I need to change some variables, but when I run, it shows that no solutions found, fsolve stopped because the last step was ineffective. However, the vector of function
values is not near zero, as measured by the value of the function tolerance.
I do not know why, can someone help me?

8 comentarios

Walter Roberson
Walter Roberson el 21 de En. de 2022
As outside observers, we have no reason to believe that there is a solution at all, or that the solution is not complex valued. If we had values for all of the variables we could take a more detailed look.
GUANGHE HUO
GUANGHE HUO el 22 de En. de 2022
Editada: Walter Roberson el 22 de En. de 2022
position=270;
delta=zeros(position,6);
delta_0=[1e-6 1e-6 1e-6 1e-6 1e-6 1e-6]; % Initial value of delta
delta(1,:)=delta_0;
for i=1:1:position
K_sp1=K_mesh_sp(i,1); K_sp2=K_mesh_sp(i,2); K_sp3=K_mesh_sp(i,3);
K_rp1=K_mesh_rp(i,1); K_rp2=K_mesh_rp(i,2); K_rp3=K_mesh_sp(i,3);
theta_s=Theta_s(i,1);
F=@(x)[ (K_sp1*x(1)*cos(alpha_tspd)-K_rp1*x(4)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp2*x(2)*cos(alpha_tspd)-K_rp2*x(5)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp3*x(3)*cos(alpha_tspd)-K_rp3*x(6)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp1*x(1)+K_sp2*x(2)+K_sp3*x(3))*cos(beta_d)*cos(alpha_tspd)*R_sd-T_in;
x(4)-theta_s*Rb_sd-x(1);
x(5)-theta_s*Rb_sd-x(2);
x(6)-theta_s*Rb_sd-x(3) ];
x0=delta(i,:);
options=optimoptions('fsolve','Algorithm','levenberg-marquardt');
delta(i+1,:)=fsolve(F,x0,options);
end
GUANGHE HUO
GUANGHE HUO el 22 de En. de 2022
Hi, Walter, these are my all variables
GUANGHE HUO
GUANGHE HUO el 22 de En. de 2022
Rb_sd=0.122867515153017
clearvars
load K_mesh_sp.mat K_mesh_sp
load K_mesh_rp.mat K_mesh_rp
load Theta_s.mat Theta_s
load alpha_tspd.mat alpha_tspd
load alpha_trpd.mat alpha_trpd
load beta_d.mat beta_d
load K_mesh_sp.mat R_pd %not in file R_pd.mat !
load R_sd.mat R_sd
load T_in.mat T_in
syms X [1 6]
Rb_sd=0.122867515153017;
position=270;
delta=zeros(position,6);
delta_0=[1e-6 1e-6 1e-6 1e-6 1e-6 1e-6]; % Initial value of delta
delta(1,:)=delta_0;
for i=1:1:position
K_sp1=K_mesh_sp(i,1); K_sp2=K_mesh_sp(i,2); K_sp3=K_mesh_sp(i,3);
K_rp1=K_mesh_rp(i,1); K_rp2=K_mesh_rp(i,2); K_rp3=K_mesh_sp(i,3);
theta_s=Theta_s(i,1);
F=@(x)[ (K_sp1*x(1)*cos(alpha_tspd)-K_rp1*x(4)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp2*x(2)*cos(alpha_tspd)-K_rp2*x(5)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp3*x(3)*cos(alpha_tspd)-K_rp3*x(6)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp1*x(1)+K_sp2*x(2)+K_sp3*x(3))*cos(beta_d)*cos(alpha_tspd)*R_sd-T_in;
x(4)-theta_s*Rb_sd-x(1);
x(5)-theta_s*Rb_sd-x(2);
x(6)-theta_s*Rb_sd-x(3) ];
x0=delta(i,:);
options=optimoptions('fsolve','Algorithm','levenberg-marquardt');
T1 = F(X);
sol = solve(T1([1:3 5:7]), X)
T2 = subs(T1(4), sol)
assert(isAlways(T2 == 0, 'unknown', 'true'), 'seventh equation fail')
delta(i+1,:)=fsolve(F,x0,options);
end
You will get seventh equation fail in the first iteration.
The last three equations are of the form Xi - Xj which forces Xi and Xj to be the same. Substitute those equalities into the first three equations and you get equations that are all linear in a single variable and the right hand side of the equation is 0. When a linear multiple of a variable must be equal to 0, then it forces the variable to be equal to 0. So the first three variables must be 0 and the last 3 variables must be the same as the first three variables and so must equal 0 as well. This leaves you with one equation out of the 7, and if you substitute in all 0 for the variables there, you get something that cannot possibly be 0.
So, at least for the first round, the equations are inconsistent.
GUANGHE HUO
GUANGHE HUO el 23 de En. de 2022
So, my problem is my equation, my equations must be checked
x(4)-theta_s*Rb_sd-x(1);
x(5)-theta_s*Rb_sd-x(2);
x(6)-theta_s*Rb_sd-x(3) ];
If theta_s happened to be 0, then those force equality relationships.
If theta_s were non-zero then those force simple linear relationships that you can substitute into the first four equations.
syms x [1 6]
syms alpha_trpd alpha_tspd beta_d K_rp1 K_rp2 K_rp3 K_sp1 K_sp2 K_sp3 R_pd R_sd Rb_sd T_in theta_s
eqn = [ (K_sp1*x(1)*cos(alpha_tspd)-K_rp1*x(4)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp2*x(2)*cos(alpha_tspd)-K_rp2*x(5)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp3*x(3)*cos(alpha_tspd)-K_rp3*x(6)*cos(alpha_trpd))*cos(beta_d)*R_pd;
(K_sp1*x(1)+K_sp2*x(2)+K_sp3*x(3))*cos(beta_d)*cos(alpha_tspd)*R_sd-T_in;
x(4)-theta_s*Rb_sd-x(1);
x(5)-theta_s*Rb_sd-x(2);
x(6)-theta_s*Rb_sd-x(3) ]
eqn = 
sol = solve(eqn([1:3 5:end]), x)
sol = struct with fields:
x1: -(K_rp1*Rb_sd*theta_s*cos(alpha_trpd))/(K_rp1*cos(alpha_trpd) - K_sp1*cos(alpha_tspd)) x2: -(K_rp2*Rb_sd*theta_s*cos(alpha_trpd))/(K_rp2*cos(alpha_trpd) - K_sp2*cos(alpha_tspd)) x3: -(K_rp3*Rb_sd*theta_s*cos(alpha_trpd))/(K_rp3*cos(alpha_trpd) - K_sp3*cos(alpha_tspd)) x4: -(K_sp1*Rb_sd*theta_s*cos(alpha_tspd))/(K_rp1*cos(alpha_trpd) - K_sp1*cos(alpha_tspd)) x5: -(K_sp2*Rb_sd*theta_s*cos(alpha_tspd))/(K_rp2*cos(alpha_trpd) - K_sp2*cos(alpha_tspd)) x6: -(K_sp3*Rb_sd*theta_s*cos(alpha_tspd))/(K_rp3*cos(alpha_trpd) - K_sp3*cos(alpha_tspd))
eqn4 = subs(eqn(4), sol)
eqn4 = 
In order for the system of equations to hold, that eqn4 would have to hold. It is independent of the x values: if it holds then there is a solution to the system, and if it does not hold then there is no solution to the system.

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Oct. de 2013

Comentada:

el 24 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by