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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by