How to use Fsolve with multiple variables

조회 수: 230 (최근 30일)
Sina
Sina 2013년 10월 22일
댓글: Walter Roberson 2022년 1월 24일
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
LAKKIMSETTI SUNANDA
LAKKIMSETTI SUNANDA 2021년 2월 1일
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 2022년 1월 21일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2013년 10월 22일
[x,fval] = fsolve(@(x) Teth3(x, P, H, L), x0);
  댓글 수: 23
Walter Roberson
Walter Roberson 2016년 11월 21일
You can send messages through my profile.
Alek Yawfimetz
Alek Yawfimetz 2020년 4월 18일
I appreciate the help Walter, I had a similar issue and this helped me solve it instantly. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Manuela Gräfe
Manuela Gräfe 2017년 4월 24일
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 2016년 11월 21일
in this paper on page 3284, they have used fsolve to solve those equations. see upper right side.
  댓글 수: 10
safi58
safi58 2016년 12월 5일
solved it!!!!!!!!
Manuela Gräfe
Manuela Gräfe 2017년 4월 24일
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 2016년 12월 6일
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 2022년 1월 21일
편집: Walter Roberson 2022년 1월 21일
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
Walter Roberson
Walter Roberson 2022년 1월 24일
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.
Walter Roberson
Walter Roberson 2022년 1월 24일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by