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

13 ビュー (過去 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 Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by