Passing the input to another function
Afficher commentaires plus anciens
Hi everyone,
I'm trying to write a function for solving 1st order ODEs: dy/dx=f(x,y(x)) using taylor methode and I want it in a seperate file than the file where the user inputs the function:
here's the main program:
clear all
syms x y
f=input('fct')
g=inline(f)
yi=taylor(g,3,5,0,1,0.1)
here's the taylor fct:
function yi=taylor(f,o,np,x0,y0,h)
% o is order
% np is number of points
% x0 is the 1st point
% y0 is the value of the solution in x0 (initial condition)
% h is the step
xi=x0:h:x0+np*h
format long
syms x y
F=symfun(f,[x y]) %here is the problem
dF(1)=F;
for i=2:o
dF(i)=diff(dF(i-1),x)+dF(1)*diff(dF(i-1),y);
end
df=matlabFunction(symfun(dF,[x y]));
yi(1)=y0;
for i=1:np
d=df(xi(i),yi(i));
r=0;
for j=1:o
r=r+((h^j)/factorial(j))*d(j);
end
yi(i+1)=yi(i)+r;
end
end
my problem is that it wouldn't let me convert the f that i have just input to symbolic, so I want to know how to pass a function that was introduced by the user to another one and use symbolic functions in it (i.e: diff)
Thank you
Réponses (1)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!