Finding the maximum value of x in a differential equation.

Click For Summary

Homework Help Overview

The discussion revolves around finding the maximum value of x in a differential equation defined by x' = 0.7548 - 599.49x^6 - 2.4038x^2 - 0.12236x^1.5, with the initial condition x(0) = 0. The original poster is attempting to implement Euler's Method in MATLAB to solve this problem.

Discussion Character

  • Exploratory, Mathematical reasoning, Problem interpretation, Assumption checking

Approaches and Questions Raised

  • Participants discuss the implementation of Euler's Method and question the choice of the time range for the simulation. There are concerns about the output values, particularly regarding the occurrence of imaginary numbers and NaN results. Some participants suggest reconsidering the range of t to avoid negative values of x, while others explore the implications of different values for b on the accuracy of the results.

Discussion Status

The discussion is ongoing, with participants providing insights into the potential issues with the code and the method being used. There is a recognition that Euler's Method may not be the best approach for this problem, and alternative methods for finding the maximum value are being considered. Some participants have pointed out the relationship between the derivative and the maximum or minimum values, which has led to further exploration of the problem.

Contextual Notes

Participants note that the original poster is constrained by the requirement to use MATLAB, which influences the choice of methods. There is also a discussion about the implications of error accumulation when changing the time range for the simulation.

theBEAST
Messages
361
Reaction score
0

Homework Statement


I want to find the maximum value of x given that the differential equation relating x is:

x' = 0.7548 - 599.49x^6 -2.4038x^2 - 0.12236x^1.5

Where x = 0 at t = 0.

I have to do this with MATLAB using Euler's Method and here is my code:

Code:
x = 0
a = 0 % initial t value
b = 1000 % final t value
N = 1000 % number of intervals

for i = 1:N-1
    x(i+1) = x(i) + (b-a)/N * (0.7546-599.49*x(i)^6 - 2.4038*x(i)^2 - 0.12236*x(i)^1.5)
end

max(x)

I get an imaginary number for the value... And most of the numbers in the vector x are NaN + NaNi.

Does anyone know what I am doing wrong?
 
Physics news on Phys.org
Looks like a, b and N never change, so the only use you make of them in the code reduces to the constant 1.
 
haruspex said:
Looks like a, b and N never change, so the only use you make of them in the code reduces to the constant 1.

Yeah so shouldn't the code output the value of x at t = (0,1,2,...,1000)?
 
theBEAST said:
Yeah so shouldn't the code output the value of x at t = (0,1,2,...,1000)?
If that's what you want, yes, but how did you pick that range? Your algorithm is shooting way beyond where you want to be and dives down to where x goes negative. Once it has done that the power of 1.5 will produce imaginary results.
Can you think of a way of determining a smaller range that should include a solution?
 
haruspex said:
If that's what you want, yes, but how did you pick that range? Your algorithm is shooting way beyond where you want to be and dives down to where x goes negative. Once it has done that the power of 1.5 will produce imaginary results.
Can you think of a way of determining a smaller range that should include a solution?

Alright, but before figuring out a smaller range... I am having problems with my code already.

So if I use a = 0 and b = 1000 I get a vector x where x(2) = 0.7546. In other words x value at t = 1 gives x = 0.7546.

NOW if I decide to use a = 0 and b = 1. Then I should expect that max(x) gives me some value greater than or equal to 0.7546. Instead it gives me 0.3074...

From this I think there is something wrong with my code...?
 
theBEAST said:
So if I use a = 0 and b = 1000 I get a vector x where x(2) = 0.7546. In other words x value at t = 1 gives x = 0.7546.

NOW if I decide to use a = 0 and b = 1. Then I should expect that max(x) gives me some value greater than or equal to 0.7546. Instead it gives me 0.3074...
With b=1000, you are effectively considering t up to 1000. x[2] corresponds to t=2. With b = 1, you are only considering t up to 1. x[2] now corresponds to t=2/1000.
Even if two setting of b encompass the maximum you're looking for, you would expect different values because of error accumulation, and it's not obvious which will give the greater value.
 
haruspex said:
With b=1000, you are effectively considering t up to 1000. x[2] corresponds to t=2. With b = 1, you are only considering t up to 1. x[2] now corresponds to t=2/1000.
Even if two setting of b encompass the maximum you're looking for, you would expect different values because of error accumulation, and it's not obvious which will give the greater value.

Ah, so the one where b = 1 would give me a more accurate value but it may not be the interval where the max is located... I tried to figure out the interval by changing the values of b but as you said that would cause error to accumulate. Right now I am not sure what to do...

As I increase b, it oscillates more and more.
 
Well, I would not be using Euler's method to solve this problem. You want the point where x'=0, so that's the same as solving 0.7548 - 599.49x6 -2.4038x2 - 0.12236x1.5 = 0, or, as a polynomial in y = √x, 0.7548 - 599.49y12 -2.4038y4 - 0.12236y3 = 0.
At the least, you could use that to get a handle on the range. Just find some smallish y, ylim, which makes the polynomial go negative. (It's going to be less than 1, right?) Set b-a = ylim2.
 
haruspex said:
Well, I would not be using Euler's method to solve this problem. You want the point where x'=0, so that's the same as solving 0.7548 - 599.49x6 -2.4038x2 - 0.12236x1.5 = 0, or, as a polynomial in y = √x, 0.7548 - 599.49y12 -2.4038y4 - 0.12236y3 = 0.
At the least, you could use that to get a handle on the range. Just find some smallish y, ylim, which makes the polynomial go negative. (It's going to be less than 1, right?) Set b-a = ylim2.

LOL wow I can't believe I forgot about that. When the derivative is zero you get either a max or min. In this case it is a max because the second derivative at the solution I got x = 0.30748 is negative!

And this corresponds to the value I get from Euler's!

Thanks!
 
  • #10
theBEAST said:
LOL wow I can't believe I forgot about that. When the derivative is zero you get either a max or min. In this case it is a max because the second derivative at the solution I got x = 0.30748 is negative!

And this corresponds to the value I get from Euler's!

Thanks!
The only reason I didn't mention this before is that you said in the OP that you had to use Euler's method. Was that not true?
 
  • #11
haruspex said:
The only reason I didn't mention this before is that you said in the OP that you had to use Euler's method. Was that not true?

Oh, the question said I had to use MATLAB so the first thing that popped up in my mind was either euler's method or ode45. But then after what you said, you can also use MATLAB to solve for the zeros of the equation, which is a much better method.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 27 ·
Replies
27
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K