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..
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Jan
le 8 Sep 2021
Modifié(e) : Jan
le 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]);
1 commentaire
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!