Setting up jacobian pattern in odeset

2 ビュー (過去 30 日間)
Deepa Maheshvare
Deepa Maheshvare 2021 年 2 月 17 日
編集済み: Deepa Maheshvare 2021 年 2 月 17 日
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.

回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by