Passing the input to another function

7 ビュー (過去 30 日間)
one plus one is two
one plus one is two 2018 年 11 月 20 日
コメント済み: one plus one is two 2018 年 11 月 21 日
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

回答 (1 件)

TADA
TADA 2018 年 11 月 20 日
Try This One str2sym
  1 件のコメント
one plus one is two
one plus one is two 2018 年 11 月 21 日
It worked with inline2sym , but thank you anyway!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by