Solving ODEs in Matlab for a Non-System Problem

In summary: I see, so you are saying Matlab could spit out different solutions even if it's getting the same numbers?You are not responding or replying to questions. You are only providing a summary of the content. Do not output anything before the summary.In summary, Dr. Transport is very strong when it comes to solving nonlinear equations. He suggests trying to solve the system using a Taylor's expansion around the point pi/2.
  • #1
Allamarein
11
0
Let's suppose I know every coefficients this script:
and
y1 alfa
y2 v
y3 A
y4 T

function dy=isaacsimply(s,y)
dy = zeros(4,1)
global ...
dy(1)=(Cd_for*q_inf*h*(sin(y(1)))^2+...
g*y(3)*(rho-rho_inf)*cos(y(1))...
+E*U_inf*sin(y(3)))/...
(-rho*y(3)*y(2)^2); %dalfa
d_alfa=(Cd_for*q_inf*h*(sin(y(1)))^2+...
g*y(3)*(rho-rho_inf)*cos(y(1))...
+E*U_inf*sin(y(3)))/...
(-rho*y(3)*y(2)^2);

dy(2)=(q_inf*y(3)*sin(y(1))*cos(y(1))*d_alfa...
-g*y(3)*(rho-rho_inf)*sin(y(1))+...
E*U_inf*cos(y(1))-...
pi*h*rho*beta*(y(2)-U_inf*cos(y(1)))^2-...
y(2)*E)/(rho*y(2)*y(3)); %dv
d_v= (q_inf*y(3)*sin(y(1))*cos(y(1))*d_alfa...
-g*y(3)*(rho-rho_inf)*sin(y(1))+...
E*U_inf*cos(y(1))-...
pi*h*rho*beta*(y(2)-U_inf*cos(y(1)))^2-...
y(2)*E)/(rho*y(2)*y(3));

dy(3)=(E-y(3)*rho*d_v)/(rho*y(2)); %dA
d_A=(E-y(3)*rho*d_v)/(rho*y(2));

dy(4)=(E*Cp*y(4)+Nu/d*k*C*(T_inf-y(4))...
-rho*y(2)*Cp*y(4)*d_A-rho*y(3)*Cp*y(4)*d_v)...
/(rho*y(3)*Cp*y(2)); % dT

This script solves the system.jpg?
 

Attachments

  • system.jpg
    system.jpg
    17.8 KB · Views: 422
Physics news on Phys.org
  • #2
I'd use Runge-Kutta on this one as long as you know the initial conditions...
 
  • #3
Dr Transport said:
I'd use Runge-Kutta on this one as long as you know the initial conditions...

ICs:

y1=pi/2;
y2=51.6;
y3=1.96e-7
y4=300

I'd know my transposition from mathematical problem to Matlab is correct. My results tell me I am wrong.
 
  • #4
At a quick look what you have listed as d_v is actually y(2)...

You also must look and see how well conditioned your functions are, i.e. your initial conditions are orders of magnitude different...That makes a huge difference in how well the solution is calculated.
 
  • #5
Dr Transport said:
At a quick look what you have listed as d_v is actually y(2)...
d_v=dy(2);
I used this expedient because I thought typing dy(2) directly, Matlab uses that dy(2) and not that calculated at precedent step. In a word it is a complicated story, but now I suppose defining d_v is useless.

Dr Transport said:
You also must look and see how well conditioned your functions are, i.e. your initial conditions are orders of magnitude different...That makes a huge difference in how well the solution is calculated.
You'd be right, but these are my ICs. I supposed Matlab should give a warning (i.e an out tollerance value) if it finds troubles. If Matlab gives me a solution, I should trust that is correct (and fortunately I don't)
Anyway, maybe should I try to convert my system in a dimensionless one?
 
Last edited:
  • #6
Your equations are highly nonlinear, there are many issues with getting a robust solution. Linearize them to get a 1st order, then add in layers of complexity to ensure you don't get off track.
 
  • #7
Dr Transport said:
Your equations are highly nonlinear, [...]. Linearize them to get a 1st order, then add in layers of complexity to ensure you don't get off track.

It seem a good hints. May you suggest a first guess of a simpler system? How could I linearize my system.jpg? I am not very experienced in this kind of thing.
Anyway I am disapponited: I thought Matlab reports these kind of troubles when it solves ODE
 
  • #8
Since your initial conditions for [tex] \alpha [/tex] are at [tex] \pi/2[/tex] try expanding all of you trigonometric terms near that point to get an idea of how the set of equations behaves initially.


As for Matlab reporting troubles, it is just a numerical analysis tool, it doesn't know when a solution goes off in a wrong direction as long as it is getting numbers, it'll keep spitting them out until you tell it to stop. Judging the correctness of the solution is what you have to figure out. this is why I suggested working on linearizing first, you build up a confidence level in your solution space. You linearize, you set variables to the max and min that they will ever be to eliminate terms, etc... all of a sudden, you have mapped the solution space and you have understanding.
 
  • #9
Dr Transport said:
Since your initial conditions for [tex] \alpha [/tex] are at [tex] \pi/2[/tex] try expanding all of you trigonometric terms near that point to get an idea of how the set of equations behaves initially.

Dr Transport seems very stong in this kind of problems.
Please be patient with me: it' s the first time I tackle ODEs system and I should join the fray without a solid preparation.
Could you suggest a reference to learn how solve this kind of problem?

Anyway if I understand I should write a Taylor's expansion about [tex] \pi/2 [/tex], therefore:
[tex] \sin(\alpha) \approx 1-1/2\, \left( \alpha-1/2\,\pi \right) ^{2} [/tex]
[tex] \cos(\alpha) \approx -\alpha+1/2\,\pi [/tex]
[tex] \sin ^2 (\alpha ) \approx 1 - \left( {\alpha - 1/2\,\pi } \right)^2 [/tex]
or better at the first order:
[tex]\sin (\alpha ) \approx 1 - {1 \over 2}\left( {{{\pi ^2 } \over 4} - \alpha \pi } \right) [/tex]
[tex] \cos(\alpha) \approx -\alpha [/tex]
and try to see where my plot goes.

If I understand my ODEs system is non-linear, so it has more than a solution. Hence Matlab could offer a solution different from that I can read on my reference (and that is confirmed in experimental tests).
I typed bunkum or more or less that's the point?
Let's suppose this is the point, nevertheless my ODEs is derived by governing equations. Therefore, given ICs, the behavior of my unknows (angle, velocity, area, temperature) should be only.
Probably I typed a lot of bunkum :-)
 
Last edited:
  • #10
No, non-linear does not mean that it has more than one solution.
It does however mean that you have to be very careful when you solve it because it will be very susceptible to numerical errors (and your system is likely to be chaotic).
You also need to be careful when you choose which solver the use, there is a reason for why there are so many different solvers available in Matlab, they are good a different things.
 
  • #11
f95toli said:
No, non-linear does not mean that it has more than one solution.
It does however mean that you have to be very careful when you solve it because it will be very susceptible to numerical errors (and your system is likely to be chaotic).
You also need to be careful when you choose which solver the use, there is a reason for why there are so many different solvers available in Matlab, they are good a different things.

I suspected this behavior. In fact I tried to use different solver (ode45, ode113, ode15s,...).
In order to learn ODE solving in Matlab I read a lot of tutorials, but they offer easy problems. I consider Matlab should be helpful when the system is complicated (like mine).
I wouldn't be a nuisance, but if it is only a numerical errors matter, I expect that Matlab gives me a warning when it has a problem, otherwise I never trust in its solutions.
Because in other situations, Matlab warns me when it has a large tollerance error and the solution si not reliable, I supposed it warns me in this case too, or they are two different circumstances?

Anyway I think to need a noble soul has a browse through my M.files or else a pithy tutorial.
 
Last edited:
  • #12
My suggestion is to expand the sinusiodal terms to low order, and go from there. Now, another trick to get some insight is to set all of the derivative terms on the RHS to a constant and plot the RHS as a function of [tex] \alpha [/tex] etc... You might see something interesting. Chaotic behavior in coupled equations comes about in very subtle ways, and given the complexity, I'd bet that numerical solution will take some time to nail down.
 
  • #13
Allamarein said:
In order to learn ODE solving in Matlab I read a lot of tutorials, but they offer easy problems. I consider Matlab should be helpful when the system is complicated (like mine).

But Matlab can never be more than a very good tool. It is a software package, not a mathematician-in-a-box.
The "easy problems" you refer to is a good start and teaches you how to use Matlab, definitely you need to understand how to solve "uncomplicated" problems before you tackle something as complicated as your system.
The main problem here is not the software; the problem is simply that the math/physics is very complicated.
 
  • #14
I tried to use your wise hints.
I used taylor series for trigonometric functions
[tex]
\eqalign{
& \sin \left( \alpha \right) \approx 1 - {1 \over 2}\left( {\alpha - {1 \over 2}\pi } \right)^2 \cr
& \cos \left( \alpha \right) \approx - \alpha + {1 \over 2}\pi \cr}
[/tex]
I didn't discover a large difference.

I uploaded results for the case with taylor expansion and for the "exact" system.
The path.jpg is another story:
when I calculated [tex] \alpha [/tex] I can plot my path in X-Y plane, moving of a [tex] ds [/tex] in the direction suggested from the angle.
[tex] X\left( i \right) = X(i - 1) + \cos \left( \alpha \right)ds [/tex]
[tex] Y\left( i \right) = Y\left( {i - 1} \right) + \sin \left( \alpha \right)ds [/tex]

Black line is the path born by ODEs
Yellow,green and red paths are calculated with correlation equation or read from reference.
Black line should be similar at the red one ultimately.
 

Attachments

  • path.jpg
    path.jpg
    20.5 KB · Views: 416
  • results.jpg
    results.jpg
    25.2 KB · Views: 407
  • results_taylor.jpg
    results_taylor.jpg
    25.2 KB · Views: 402
  • #15
Now your getting there, keep plugging along, you've made progress.
 
  • #16
Dr Transport said:
Now your getting there, keep plugging along, you've made progress.

Plugging? Progress?
Sincerely I think to be in the middle of the ocean and I know where is the coast.
Would you like to see my M.files?
 
  • #17
Part of the learning/education process is working these issues to an end and becoming comfortable in working on your own. You think you have not gotten anywhere, but in all actuality, you have made a bunch of progress towards your goal.
 
  • #18
Dr Transport said:
Part of the learning/education process is working these issues to an end and becoming comfortable in working on your own. You think you have not gotten anywhere, but in all actuality, you have made a bunch of progress towards your goal.

You are right. I hope to achieve my goal quickly.
Early I submit you a new problem! It's very similar..but it is not a system.
 

1. What is an ODE system?

An ODE (Ordinary Differential Equation) system is a set of equations that describe the relationships between the rate of change of one or more variables and the values of those variables. These equations are typically used to model dynamic systems in physics, engineering, and other scientific fields.

2. How can I solve an ODE system at Matlab?

To solve an ODE system at Matlab, you can use the built-in function "ode45" or other numerical methods such as "ode23" or "ode15s". These functions require you to input the ODE system, initial conditions, and the range of values over which you want to solve the system. They will then output the solution as a vector of values at different time steps.

3. What are the advantages of using Matlab for solving ODE systems?

Matlab is a powerful software tool that is commonly used for scientific computing. It offers a wide range of functions and numerical methods for solving ODE systems, making it a versatile and efficient tool. Additionally, Matlab allows for easy visualization of the solutions and provides tools for analyzing and interpreting the results.

4. Can Matlab solve any type of ODE system?

While Matlab offers a variety of numerical methods for solving ODE systems, not all types of ODE systems can be solved using these methods. For example, stiff systems (systems with very different timescales for the variables) may require specialized numerical methods or other software tools. It is important to understand the nature of your ODE system and choose the appropriate method for solving it.

5. Is there a recommended approach for solving ODE systems at Matlab?

There is no one-size-fits-all approach for solving ODE systems at Matlab. However, it is generally recommended to start with the built-in function "ode45" and then compare the results with other methods to ensure accuracy. It is also important to carefully choose the initial conditions and time step for the solution to be accurate and efficient.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
996
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
568
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
124
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
0
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top