I am running an ode45 to solve a simple intergration. The intergration is so simple I can perform it by hand - hence knowing the solution returned is excessively large.
function [Output] = ContinuousFeed(t,u)
uA = u(1);
uB = u(2);
uE = u(3);
uF = u(4);
u = [uA; uB; uE; uF];
Output = u;
end
t=[0 10];
u0 = [1; 0.0002; 0; 0];
[t, u] = ode45 (@ContinuousFeed, t ,u0);
Why is it returning a final value of 22030.53 for the first column? All other columns are displaying inaccurate answers also.
Thank you!

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 17일
편집: Ameer Hamza 2020년 3월 17일

0 개 추천

The MATLAB is giving the correct solution. You are solving four independent ODEs of the form
which have an anatylical solution
The solution of ode45 matches this analytical solution.

댓글 수: 7

Koren Murphy
Koren Murphy 2020년 3월 17일
U is meant to be a constant however, so how should this be implemented to give a solution of;
int u = [u*tj - u*ti]?
Koren Murphy
Koren Murphy 2020년 3월 17일
or the simplfied answer of (u*t + C), if integration limits are not specified
Ameer Hamza
Ameer Hamza 2020년 3월 17일
I am not sure about your comment. Can you show the mathematical form of the differential equations?
Koren Murphy
Koren Murphy 2020년 3월 17일
This is the equation i have to integrate. U is a constant feed rate, however, must be intregated to solve a larger problem. I have used ode45 to solve other aspects of the problem but as it it solving using a linear equation the solution is accurate.
I really appreciate your assistance.
Steven Lord
Steven Lord 2020년 3월 17일
편집: Steven Lord 2020년 3월 17일
Be careful with your variables. I think you're overloading the variable u with two meanings.
Do you want to solve the system or the system ? If the latter your ODE function should be:
function dudt = ContinuousFeed(t, u)
yourConstantVector = [1; 2; 3; 4]; % For example
dudt = yourConstantVector;
end
Note that nothing in this version of ContinuousFeed depends on the time t or the function u at all so you could replace them with ~ (to tell MATLAB explicitly that ContinuousFeed doesn't use thoe inputs.)
function dudt = ContinuousFeed(~, ~)
yourConstantVector = [1; 2; 3; 4]; % For example
dudt = yourConstantVector;
end
I have applied this Steven and it has stopped the exponential. However, it appears to be adding the original feed to the solutions as it goes
function dudt = ContinuousFeed(~, ~);
ConstantVector = [1; 0.0002; 0; 0]; % initial conditions
dudt = ConstantVector;
end
r = 1e-6;
t = [0 10 10+r 20 20+r 30 30+r 40 40+r 50]; % this is assuming a sample taken every 10 units of time.
% tspan must constantly
% increase or decreases to
% work hence the addition of 1e-6
u0 = [1; 0.0002; 0; 0];
Therefore it is returning the solutions;
1
11
11.000001
21
21.000001
31
31.000001
41.
41.000001
51.
Ameer Hamza
Ameer Hamza 2020년 3월 17일
If my initial feed you meant initial conditions, then this is the expected behavior. Vector u0 tells the ode45 where to start the solution of each variable.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2020년 3월 17일

댓글:

2020년 3월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by