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..

11 Ansichten (letzte 30 Tage)
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');

Akzeptierte Antwort

Jan
Jan am 8 Sep. 2021
Bearbeitet: Jan am 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]);

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by