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..
1 view (last 30 days)
Show older comments
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');
0 Comments
Accepted Answer
Jan
on 8 Sep 2021
Edited: Jan
on 8 Sep 2021
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]);
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!