Reputation: 147
I'm trying to solve differential equation using ode45 function.
where parameters C1, C2, C3 and C4 are column vector in size of 1:1001. What I want to do is I need to put them inside of function that ode45 is referring (fun.m) to and use them in equation, but I want the values to change after every iteration. So, for example, at the beginning C1 value I want in is C1(1), the next iteration it's C1(2), next iteration it's C1(3) etc.
My code:
[t1,X2]=deal(cell(numel(C1),1));
[t1,X2]=deal(cell(numel(C2),1));
[t1,X2]=deal(cell(numel(C3),1));
[t1,X2]=deal(cell(numel(C4),1));
for k = 1:numel(C1)
[t1{k},X2{k}] = ode45(@(t,x)fun(t,x,C1(k),C2(k),C3(k),C4(k)),t0,X01);
end
The code started to give me 1001x1 cell that has only brackets, like this "[]" and each bracket is empty inside. Each C is 1x1001 double and has values in it.
Upvotes: 0
Views: 72
Reputation: 751
You C1
to C4
are cell not matrix. So if you access it this way:
C1(k)
The result will be:
ans =
1×1 cell array
{value}
But you need this value directly, so simple call:
C1{k}
And get this answer:
ans =
value
Here is your solver call, with presented changes:
[t1{k},X2{k}] = ode45(@(t,x)fun(t,x,C1{k},C2{k},C3{k},C4{k}),t0,X01);
Upvotes: 1