Reputation: 1
i want to change function variable at each step in a for loop in matlab. i take these steps: i created my mfile function
function [jfun,fun]=air(x,vt,ty,tz,p2,y0)
jfun=[(cos(tz)*cos(ty)*vt/9.81)*(1-exp(-9.81*x(2)/vt)),...
x(1)*cos(tz)*cos(ty)*exp(-9.81*x(1)/vt);
(-vt*sin(tz)*cos(ty)/9.81)*exp(-9.81*x(1)/vt),...
(x(1)*sin(tz)*cos(ty)*+vt)*exp(-9.81*x(1)/vt)];
fun=[(x(1)*cos(ty)*cos(tz)*vt/9.81)*(1-exp(-9.81*x(2)/vt))-p2;...
(vt/9.81)*(x(1)*sin(tz)*cos(ty)+vt)*(1-exp(-9.81*x(2)/vt))-vt*x(2)+y0];
end
and then i used newtonSys command:
ty=rad(-23)
tz=rad(15)
p2=1.8
vt=8.4925
y0=0.2
myfun=@(x)air(x,vt,ty,tz,p2,y0)
x=newtonSys(myfun,[15 5],0.000001,0.000001,500,1)
and matlab answer: Error in ==> Untitled18 at 7 x=newtonSys(myfun,[15 5],0.000001,0.000001,500,1) i guess that its because of wrong use of function handle and for my function i have to use another command or i have to use another method for solving 2nonlinear equation.
Upvotes: 0
Views: 244
Reputation: 42225
First, you haven't displayed the entire error. MATLAB should tell you what the actual error is, so unless you tell us that, we won't know what's wrong.
Secondly I don't see newtonSys
in my system, or in the online MATLAB documentation. So most likely it is an external program, which most people here might not be familiar with. The closest I found from a quick Google search was this, which is an implementation of Newton's method for approximating the root of a non-linear system of n-equations. Are you using the same file? If so, if you look at the comments, it says that you need to pass the function as a string. So you'd have to pass myfun
as 'myfun'
.
If not, could you edit your question and add the contents of the function that you're using? Without these, it's near impossible to answer your question.
Upvotes: 1