Solving non-linear parametric system of equations

Hi everyone
I've been struggling to solve a non-linear system of parametric equations for a certain range of of values with the command fsolve.
Here is my discribed system function :
function F=thsol(th)
th3=1
F = @(th) [1.*cos(th1)+0.6.*cos(th2)+0.2.*cos(th3)
1.*sin(th1)+0.6.*sin(th2)+0.2.*sin(th3)-1];
this works :
sol = fsolve (thsol(th),[1,1])
but when i define th3 as a variable as followed :
function F=thsol(th,th3)
F = @(th,th3) [1.*cos(th1)+0.6.*cos(th2)+0.2.*cos(th3)
1.*sin(th1)+0.6.*sin(th2)+0.2.*sin(th3)-1];
and write down :
th3=1
sol = fsolve (@(th) thsol(th,th3),[1,1])
i get this :
"Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using
Levenberg-Marquardt algorithm instead.
> In fsolve at 314
??? Undefined function or method 'isfinite' for input arguments of type 'function_handle'.
Error in ==> levenbergMarquardt at 14
if any(~isfinite(costFun))
Error in ==> fsolve at 373
[x,FVAL,JACOB,EXITFLAG,OUTPUT,msgData] = ..."
I really don't get what's going wrong since i'm trying to solve the exact same system with the exact same values, only calling th3 as variable parameter. Anyone could tell me where i went wrong? thank you all

댓글 수: 2

Ignacio can you try formatting the code using the {}Code button?
done. ;)

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

 채택된 답변

Shashank Prasanna
Shashank Prasanna 2013년 5월 2일

0 개 추천

It seems that the function thsol returns a function handle instead of a vector for the output F.
Your first call:
sol = fsolve (thsol(th),[1,1])
does pass the function handle, which is the output of thsol(th)
sol = fsolve (@(th) thsol(th,th3),[1,1])
Here thsol still returns a function handle which is wrapped around another function handle which is not the expected input for fsolve.
Try the following
F = @(th,th3) [1.*cos(th1)+0.6.*cos(th2)+0.2.*cos(th3) 1.*sin(th1)+0.6.*sin(th2)+0.2.*sin(th3)-1];
th3=1;
sol = fsolve(@(th)F(th,th3),[1,1])

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by