please help me with this problem,
i want to solve ODEs many times with different value of "v2" variable,
so i use if statement to loop it, but the output of X2 look wrong especially its size (41x4)
i try 1 time solving with one value of "v2" only, it turns out size of X2 is about 6000x4
here's the code
x_extend = zeros(121,1);
x_compress = zeros(121,1);
v2=0;
for i=0:1:120
v2=v2+i;
save input.mat
t_end = 2.5;
TSPAN = [0 t_end]; %Solving duration
IC = [0; 0; 0; 0]; %Initial conditions
[T2, X2]= ode45(@PTVP2, TSPAN, IC,options);
a=X2(:,3)-X2(:,1);
x_extend(i+1) = max(a);
x_compress(i+1) = min(a);
end

 Accepted Answer

You are not saving values of X in each iteration
x_extend = zeros(121,1);
x_compress = zeros(121,1);
v2=0;
Ts = cell(121,1);
Xs = cell(121,1);
for i=0:1:120
v2=v2+i; % is this correct??? Or do you want v2=i???
save input.mat
t_end = 2.5;
TSPAN = [0 t_end]; %Solving duration
IC = [0; 0; 0; 0]; %Initial conditions
[T2, X2]= ode45(@PTVP2, TSPAN, IC,options);
a=X2(:,3)-X2(:,1);
x_extend(i+1) = max(a);
x_compress(i+1) = min(a);
Ts{i} = T2;
Xs{i} = X2;
end
This creates cell array T2 and X2 which save results for each iteration.

2 Comments

I got it, thanks very much, i have to be v2=i!
I am glad to be of help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!