# How to use Fsolve with multiple variables

1.402 views (last 30 days)
Sina on 22 Oct 2013
Commented: Alek Yawfimetz on 18 Apr 2020
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.

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

umme mumtahina on 21 Nov 2016
Walter you are a legend. Thank you very much. Can I have your contact details please?
Walter Roberson on 21 Nov 2016
You can send messages through my profile.
Alek Yawfimetz on 18 Apr 2020
I appreciate the help Walter, I had a similar issue and this helped me solve it instantly. Thanks.

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

umme mumtahina on 4 Dec 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.
umme mumtahina on 5 Dec 2016
solved it!!!!!!!!
Manuela Gräfe on 24 Apr 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.

umme mumtahina on 6 Dec 2016
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

Manuela Gräfe on 24 Apr 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.