Plot ODE Bond Price Model

1 Ansicht (letzte 30 Tage)
Joseph Zinno
Joseph Zinno am 10 Dez. 2019
Beantwortet: Star Strider am 10 Dez. 2019
How would you plot this ODE in matlab?
dB/dt = r(t)*B-k(t)

Antworten (1)

Star Strider
Star Strider am 10 Dez. 2019
Not enough information, so I created the missing variables:
tv = linspace(0, 100, 25); % Time Vector Common To ‘r’ And ‘k’
rv = randn(1,25); % Create ‘r’
kv = randn(1,25); % Create ‘k’
ODEfcn = @(t,B) interp1(tv,rv,t)*B-interp1(tv,kv,t);
B0 = 4.2;
tspan = [0 15];
[T,B] = ode45(ODEfcn, tspan, B0);
figure
plot(T,B)
grid
This runs without error.
Experiment with the actual vectors for ‘r’ and ‘k’ to get the correct result.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by