Setting up jacobian pattern in odeset

2 Ansichten (letzte 30 Tage)
Deepa Maheshvare
Deepa Maheshvare am 17 Feb. 2021
Bearbeitet: Deepa Maheshvare am 17 Feb. 2021
Hi All,
I'm trying to evaluate the jacobian pattern for a toy model
x0 = [1 0 0 0 0 0 0 0 0 0]';
tspan = 0:0.01:5;
f0 = fun(0, x0);
J = odenumjac(fun,{0 x0}, f0);
sparsity_pattern = sparse(J~=0.);
options = odeset('Stats', 'on', 'JPattern', sparsity_pattern);
[t, sol] = ode15s(@(t,x) fun(t,x), tspan , x0);
plot(t, sol)
function f = fun(t,x)
mat1=[
1 -2 1 0 0 0 0 0 0 0;
0 1 -2 1 0 0 0 0 0 0;
0 0 1 -2 1 0 0 0 0 0;
0 0 0 1 -2 1 0 0 0 0;
0 0 0 0 1 -2 1 0 0 0;
0 0 0 0 0 1 -2 1 0 0;
0 0 0 0 0 0 1 -2 1 0;
0 0 0 0 0 0 0 1 -2 1;
];
mat2 = [
1 -1 0 0 0 0 0 0 0 0;
0 1 -1 0 0 0 0 0 0 0;
0 0 1 -1 0 0 0 0 0 0;
0 0 0 1 -1 0 0 0 0 0;
0 0 0 0 1 -1 0 0 0 0;
0 0 0 0 0 1 -1 0 0 0;
0 0 0 0 0 0 1 -1 0 0;
0 0 0 0 0 0 0 1 -1 0;
];
f(1,1) = 0;
f(2:9,1) = mat1*x + mat2*x;
f(10,1) = 2*(x(end-1) - x(end));
end
I get the following error and unfortunately I couldn't figure out how to fix this error
Not enough input arguments.
Error in Untitled>fun (line 36)
f(2:9,1) = mat1*x + mat2*x;
Error in Untitled (line 5)
J = odenumjac(fun,{0 x0}, f0);
Suggestions on how to fix this will be really helpful.

Antworten (0)

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by