Azzera filtri
Azzera filtri

Can't solve ODE with pchip and ppval

3 visualizzazioni (ultimi 30 giorni)
Philip Berg
Philip Berg il 7 Nov 2016
Commentato: Jan il 8 Nov 2016

Hi, I'm getting a error I can't understand and I would love if someone could clarify for me why the following doesn't work: I have two ode's, one with and one without noise. The one with works, but the one without doesn't. The one without looks like this:

function [dFTdt] = SVP(t,x,p,SVP)
alpha = p(1);
beta = p(2);
ki=p(3);
FT=x(1);
dFTdt = zeros(1,1);
dFTdt(1)=beta - ppval(SVP,t) * ki - FT * alpha;
end

and the one with like this:

function [dFTdt] = SVPnoise(t,x,p,SVP)
alpha = p(1);
beta = p(2);
ki=p(3);
FT=x(1);
dFTdt = zeros(1,1);
dFTdt(1)=beta - ppval(SVP,t) * ki - FT * alpha + normrnd(0,0.5);
end

I can solve the one with noise in the following way:

[~,yx] = ode45(@(t,x) SVPnoise(t,x,BestLSQ12,SVP12),tData,FT(1,1))

where

BestLSQ12 = [327.1456  591.7595  471.9959]; SVP(:,1) = 0.5000 0.8000 0.3000 0.7500 0.5000 0.2500 0.2300 0.4000 0.2400 0.2000 0.7000 0.3500 0.3500 1.0100]; tData = 1.0000 1.3300 1.6600 2.0000 2.3300 2.6600 3.0000 3.3300 3.6600 4.0000 4.3300 4.6600 5.0000 5.3300]; SVP12 = pchip(tData,SVP(:,1)); FT(1,1) = 0.1000; 

I solve the one without noise in the following way:

[~,yx] = ode45(@(t,x) SVP(t,x,BestLSQ12,SVP12),tData,FT(1,1))

and then I get the following error:

Function 'subsindex' is not defined for values of class 'struct'.
Error in @(t,x)SVP(t,x,BestLSQ22,SVP12)
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

I'm still a MATLAB novice, so I have no idea why this appears. I would love to know for future progress. If anyone care to write a short line about it---I would be very grateful. //Best regards

Risposta accettata

Jan
Jan il 7 Nov 2016
Please check if "SVP" is treated as function handle:
which('SVP')
before the line:
[~,yx] = ode45(@(t,x) SVP(t,x,BestLSQ12,SVP12),tData,FT(1,1))
The message might mean, that "SVP" is a struct here.
If this is not the problem, use the debugger for a deeper investigation:
dbstop if error
Now Matlab stops, when the error occurs. Then check the classes of the variables
SVP, t,x,BestLSQ22,SVP12
  5 Commenti
Torsten
Torsten il 8 Nov 2016
A sidenote: it does not make sense to include random variables in a usual numerical integration with ODE45.
You will have to switch to solution methods for stochastic differential equations.
Best wishes
Torsten.
Jan
Jan il 8 Nov 2016
Exactly, Torsten is right. I have not seen the random values. Matlab's ODE integrators handle only smooth functions correctly. With random or discontinous values, the step size control drives crazy and you get either very noisy results caused by the accumulation of rounding errors and tiny step sizes, or the integration stops. If you get a "result" it might be dominated by the rounding error, not by the noise injected in teh data.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by