Trouble with inline functions.

조회 수: 5 (최근 30일)
Ben Bowman
Ben Bowman 2019년 11월 27일
댓글: Ben Bowman 2019년 11월 28일
My homework says to use this code:
f = inline('[x(2);-sin(x(1))]', 't' , 'x');
xystart = [2 1]; tEnd=30;
[t,xa] =ode45(f,[0,tEnd],xystart);
k2 = min(find(t>2))
xa(k2,:)
as an example of how to solve a systme of differential equations, but I'm using using version R2019b and the assignment directions were written for an older version.
When I use the code from the instructions MATLAB throws this error:
Error using inline/horzcat (line 7)
Inline functions can't be concatenated.
Error in odefcncleanup (line 15)
[~,oldFcnFun] = evalc(['@' oldFcn]);
Error in ode45 (line 274)
odeFcn_main = odefcncleanup(FcnUsed,odeFcn,odeArgs);
Error in project5_task13 (line 4)
[t,xa] =ode45(f,[0,tEnd],xystart);
This is the first time I've seen the "inline" command so I'm not sure what it's trying to do much less how to fix it.
Please help.
Thank you.
  댓글 수: 2
Stephen23
Stephen23 2019년 11월 27일
편집: Stephen23 2019년 11월 27일
"My homework says to use this code... inline..."
Make a formal complaint to your school/college/university that their teaching material is totally outdated (and was apparently written in the grand-ol-days when your teacher/tutor/professor first learned to write code on punch cards and they don't see any reason to keep up with the world...)
You should read the inline documentation yourself, which clearly states at the very top:
Capture.PNG
And then learn about anonymous functions and function handles: you will gain some still-relevant skills, unlike your sadly very outdated teacher/tutor/professor.
James Tursa
James Tursa 2019년 11월 27일
+1

댓글을 달려면 로그인하십시오.

채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 11월 27일
inline is replaced by handles function:
f = @(t,x) [x(2);-sin(x(1))];
xystart = [2 1]; tEnd=30;
[t,xa] =ode45(f,[0,tEnd],xystart);
k2 = min(find(t>2))
xa(k2,:)
  댓글 수: 1
Ben Bowman
Ben Bowman 2019년 11월 28일
Thank you. This works good and gives me the format I need to finish the rest of the assignment.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by