Why ode45 is not working??
Show older comments
Hello,
I've uploaded the two following files:
1. epas_steering_system.m is the main file, and it is the file where ode45 gives me an error,
2. epasFun.m is the function file.
My question is, does somebody know why ode45 won't work?
Thanks.
35 Comments
Frane
on 19 Jul 2021
1 The definition of I from Ms must be done elementwise:
for i = 1:numel(time)
if Ms(i) >= 3.5
I(i) = ...
....
end
2 Ms(x), I(x) and Fr(x) in the list of parameters are incorrect.
Make a loop when calling the ode solver over the number of elements in the array time:
for i = 1:numel(time)
[T{i},X{i}] = ode45(@(t,x) epasFun(x,...,Ms(i),I(i),Fr(i)),...
end
Torsten
on 19 Jul 2021
Again look at the necessary changes to be made I indicated in my response.
You didn't incorporate them properly in your code.
Frane
on 19 Jul 2021
Frane
on 19 Jul 2021
Torsten
on 19 Jul 2021
What is the error message ?
Frane
on 19 Jul 2021
One error is that you must replace Fr(i) by Fr in the list of parameters handed to epasFun because Fr=1 is a scalar.
If the error persists, check the size of all variables handed to epasFun in this function. One of them must have size 3x9 instead of 1. So insert the lines
size(x)
size(Juc)
size(Jlc)
etc
at the beginning of function epasFun.
Frane
on 19 Jul 2021
Torsten
on 20 Jul 2021
You overwrote the scalar value for K by K = lqr(A,B,Q,R). Use another name here.
Frane
on 20 Jul 2021
Torsten
on 20 Jul 2021
I'm not completely sure how to deal with the cell arrays T and X. So to keep control, change the last part of the code to
tspan = 0:0.1:3;
x0 = zeros(9,1);
X = zeros(numel(time),numel(tspan),9);
for i = 1:numel(time)
[t,x] = ode45(...);
X(i,:,:) = x(:,:);
end
Now you can plot, e.g. all nine components of the solution for Ms(1) and I(1) :
plot (t,X(1,:,:))
Frane
on 20 Jul 2021
Torsten
on 20 Jul 2021
plot (t,squeeze(X(1,:,:)))
Frane
on 20 Jul 2021
Torsten
on 20 Jul 2021
Plot shows the 8th solution variable over time for (Ms(1),I(1)), (Ms(2),I(2)),...,Ms(numel(time)),I(numel(time))) (thus there should be 20 curves because numel(time) = 20, I guess).
Frane
on 20 Jul 2021
Torsten
on 20 Jul 2021
help xlim
help ylim
Torsten
on 20 Jul 2021
If you now tell me that Ms and I are interpolation curves dependent on t and that the values Ms(t) and I(t) have to be inserted in the equations when the solver has reached time t, we can start anew modifying your code.
Torsten
on 20 Jul 2021
And why do these quantities depend on time ?
Torsten
on 20 Jul 2021
At the moment, the equations are solved for Ms and I being fixed parameter values over the integration time. Thus for each combination for Ms and I (and there exist as many combinations as the vector "time" has elements), you get 9 solution curves over the time period defined by "tspan". I suspect that the time instants specified in "time" and "tspan " must be identical and that the values of Ms and I must be interpolated to the integration time provided by ODE45 in function epasFun. But this is not what is simulated in the actual code.
Frane
on 20 Jul 2021
Frane
on 21 Jul 2021
Torsten
on 21 Jul 2021
Sorry, but I have no experience with the output of function "stepplot".
You should open a new question.
Frane
on 21 Jul 2021
Torsten
on 21 Jul 2021
According to the equations you posted, they seem to be implemented correctly in epasFun.
Of course, I can't tell whether they are correct or whether the parameters you chose make sense.
Frane
on 22 Jul 2021
Answers (1)
Tesfaye Girma
on 21 Jul 2021
you can try this approach if it worked for you
f = (t,y) [ 4.86*y(3) - 4.86*10^14*y(1)*y(2);
4.86*y(3) - 4.86*10^14*y(1)*y(2);
-4.86*y(3) + 4.86*10^14*y(1)*y(2) ];
opt = odeset('maxstep',1e-13);
tspan = [0 1e-11];
y0 = [1.48e-8; 6.7608e-3; 1];
[t,y] = ode45(f,tspan,y0,opt);
subplot(311)
plot(t,y(:,1))
subplot(312)
plot(t,y(:,2))
subplot(313)
plot(t,y(:,3))
3 Comments
Ildeberto de los Santos Ruiz
on 21 Jul 2021
The @ character is missing when you define
.
f = @(t,y) [...
Tesfaye Girma
on 22 Jul 2021
you are right thank you brother!!
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!











