Why ode45 is not working??
이전 댓글 표시
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
Frane
2021년 7월 19일
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
2021년 7월 19일
Again look at the necessary changes to be made I indicated in my response.
You didn't incorporate them properly in your code.
Frane
2021년 7월 19일
Frane
2021년 7월 19일
Torsten
2021년 7월 19일
What is the error message ?
Frane
2021년 7월 19일
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
2021년 7월 19일
Torsten
2021년 7월 20일
You overwrote the scalar value for K by K = lqr(A,B,Q,R). Use another name here.
Frane
2021년 7월 20일
Torsten
2021년 7월 20일
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
2021년 7월 20일
Torsten
2021년 7월 20일
plot (t,squeeze(X(1,:,:)))
Frane
2021년 7월 20일
Torsten
2021년 7월 20일
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
2021년 7월 20일
Torsten
2021년 7월 20일
help xlim
help ylim
Torsten
2021년 7월 20일
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
2021년 7월 20일
And why do these quantities depend on time ?
Torsten
2021년 7월 20일
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
2021년 7월 20일
Frane
2021년 7월 21일
Torsten
2021년 7월 21일
Sorry, but I have no experience with the output of function "stepplot".
You should open a new question.
Frane
2021년 7월 21일
Torsten
2021년 7월 21일
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
2021년 7월 22일
답변 (1개)
Tesfaye Girma
2021년 7월 21일
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
Ildeberto de los Santos Ruiz
2021년 7월 21일
The @ character is missing when you define
.
f = @(t,y) [...
Tesfaye Girma
2021년 7월 22일
you are right thank you brother!!
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!












