in this code for solving ODE using ode45, I am having problem with 'inline' function. Which function can be used instead of it?? Kindly guide me about it..

조회 수: 2 (최근 30일)
function dy= myodein
dy=zeros(1,1);
clear all;
ytemp2= input('Enter the RHS of dy/dt: ', 's');
ytempi= strrep(ytemp2,'*','.*');
ytempj= strrep(ytempi,'/','./');
ytemp3= strrep(ytempj,'^','.^');
ytemp4= inline(ytemp3,'t','y');
dy(1)= ytemp4;
options= odeset('RelTol',1e-4,'AbsTol',1e-4);
lower=input('Enter the lower limit of integration: ');
upper=input('Enter the upper limit of integration: ');
initialval=input('Enter the initial value for y: ');
[T,Y] = ode45(dy,[lower upper],initialval,options);
plot(T,Y,'k-','LineWidth',2);
get(gcf,'CurrentAxes');
h=gca;
set(h,'YGrid','on');
ylabel('\fontsize{14 \bf y value'),xlabel('\fontsize{14} \bf time, t');

채택된 답변

Jan
Jan 2021년 9월 8일
편집: Jan 2021년 9월 8일
Do not use clear all inside a function. A good idea would be to avoid this brute clearing in general. But here it is really useless:
function dy= myodein
dy=zeros(1,1);
clear all;
...
You create the variable dy and remove all variables in the next line.
Use str2func to create the function handle:
ytemp4= str2func(['@(t, y)', ytemp3]);

추가 답변 (0개)

카테고리

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