Passing the input to another function

9 visualizaciones (últimos 30 días)
one plus one is two
one plus one is two el 20 de Nov. de 2018
Comentada: one plus one is two el 21 de Nov. de 2018
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

Respuestas (1)

TADA
TADA el 20 de Nov. de 2018
Try This One str2sym
  1 comentario
one plus one is two
one plus one is two el 21 de Nov. de 2018
It worked with inline2sym , but thank you anyway!

Iniciar sesión para comentar.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by