[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: a deval function for octave
From: |
Carlo De Falco |
Subject: |
Re: a deval function for octave |
Date: |
Mon, 27 May 2019 09:27:05 +0000 |
Dear Philippe,
> Il giorno 24 mag 2019, alle ore 11:55, philippe <address@hidden> ha scritto:
>
> Hi to all
>
> the syntax to solve a differential equation in matlab has recently
> changed and became incompatible with the octave one ! Actually you
> should do :
>
> %% solving y''(t)+y(t)=0 y(0)=y'(0)=1 => y(t)=cos(t)+sin(t)
> y0=[1;1];T=40; %%
> t=[0:0.1:T]; %% you choose times t(k) where solution is evaluated
> sol=ode45(@(t,y) [y(2);-y(1)],[0,T],y0); %% solving (E)
> tt=sol.x;y=sol.y; %% retrieve tt and y(tt) vectors
> clf ; %% plotting numerical and exact solutions
> plot(tt,y(1,:),'xr',t,cos(t)+sin(t),'-b')
>
> but the problem is that you can’t choose times tt computed with ode45 ,
> if you want more points you need to do an interpolation between those
> computed by ode45 … in matlab this is done by deval function :
This does not seem a recent change to me, AFAIK this syntax has been there for
a while (for decades if I am not wrong) ...
If you want your solution to be evaluated a specific points you actually can,
just use the syntax (either matlab or octave):
y0=[1;1];
T=40;
t=[0:0.1:T];%% you choose times t(k) where solution is evaluated
[~, y] = ode45(@(t,y) [y(2);-y(1)], t, y0);
plot (t, y(1,:), 'xr', t, cos(t)+sin(t),'-b')
>
> y0=[1;1];T=40;%%
> t=[0:0.1:T];%% you choose times t(k) where solution is evaluated
> sol=ode45(@(t,y) [y(2);-y(1)],[0,T],y0);
> y=deval(t,sol);
> clf ; %% plotting numerical and exact solutions
> plot(t,y(1,:),'xr',t,cos(t)+sin(t),'-b')
>
> but deval has not yet been implemented in octave !!! So I’ve tried to
> implement my own one (see below), can it be useful to share it here?
Your current implementation is not consistent with the numerical method used by
ode45 and is
not compatible with matlab, also it does not take into consideration the other
ode integrators.
If you are interested in working on a compatible and consistent implementation
of deval
that would indeed be a welcom addition to Octave!
> sincerely yours ,
> Philippe
c.