i have a set of3 nonlinear equations and i need to solve them by using fsolve in matlab
function F = root2d(y)
syms b1 b2 b3 w21 w31 theta1 theta2 theta3 a1 a2 a3;
F(1) = (1+exp(-b1*(w21*y(2)+w31*y(3)-theta1)))^(-1) - a1*y(1);
F(2) = (1/(1+exp(-b2*(y(1)-theta2))))-a2*y(2);
F(3)= (1/(1+exp(-b3*(y(1)-theta3))))-a3*y(3);
this is my function matlab file. I call this matlab function while using the matlab file
fun = @root2d;
x0 = [0,0,0];
x = fsolve(fun,x0)
But it is giving me the error
Error using fsolve (line 258)
FSOLVE requires all values returned by user functions to be of data type double.
Error in Untitled5 (line 3)
x = fsolve(fun,x0)
can somebody help ?

답변 (1개)

Matt J
Matt J 2017년 12월 10일
편집: Matt J 2017년 12월 10일

0 개 추천

FSOLVE does not handle symbolic variables, so get rid of the line
syms b1 b2 b3 w21 w31 theta1 theta2 theta3 a1 a2 a3
and substitute these quantities with actual numeric values.

댓글 수: 8

actually i want to get the answer in terms of variables only. how can it be done
Matt J
Matt J 2017년 12월 10일
편집: Matt J 2017년 12월 10일
I doubt that's possible for these particular equations, but if it is possible it would be with the SOLVE command, but not with FSOLVE.
myetceteramail myetceteramail
myetceteramail myetceteramail 2017년 12월 10일
편집: Matt J 2017년 12월 10일
with solve i get the error
Error in solve (line 227)
[eqns,vars,options] = getEqns(varargin{:});
Matt J
Matt J 2017년 12월 10일
편집: Matt J 2017년 12월 10일
You have not shown your code nor the complete error message so, hard to advise.
Error using root2d (line 3)
Not enough input arguments.
Error in sym>funchandle2ref (line 1211)
S = sym(x());
Error in sym>tomupad (line 1114)
x = funchandle2ref(x);
Error in sym (line 151)
S.s = tomupad(x);
Error in solve>getEqns (line 410)
a = formula(sym(a));
Error in solve (line 227)
[eqns,vars,options] = getEqns(varargin{:});
Error in Untitled5 (line 3)
x = solve(fun,x0);
Matt J
Matt J 2017년 12월 10일
Still don't see the new code you're running.
function F = root2d(y)
syms b1 b2 b3 w21 w31 theta1 theta2 theta3 a1 a2 a3;
F(1) = (1+exp(-b1*(w21*y(2)+w31*y(3)-theta1)))^(-1) - a1*y(1);
F(2) = (1/(1+exp(-b2*(y(1)-theta2))))-a2*y(2);
F(3)= (1/(1+exp(-b3*(y(1)-theta3))))-a3*y(3);
fun = @root2d;
x0 = [0,0,0];
x = solve(fun,x0);
Matt J
Matt J 2017년 12월 10일
To clarify what I said before, you must use the SOLVE command, but you should first read its documentation so you can use it correctly!

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

태그

댓글:

2017년 12월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by