Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Math and Science (http://www.chiefdelphi.com/forums/forumdisplay.php?f=70)
-   -   numerical solution of differential equations (http://www.chiefdelphi.com/forums/showthread.php?t=152790)

Hitchhiker 42 23-12-2016 21:52

Re: numerical solution of differential equations
 
Quote:

Originally Posted by Ether (Post 1623250)


@Mark: Where did you get the accel formula for columns D and G.



Not sure. Must have been really tired :) . I did that over, and also added an error column to show the difference between Xa and the predicted X (Xm or Xe).
I set dt = 0.01 s and compared the errors at t = 1, 2, 4 s

For 1s:
Midpt error: 0.598
Euler error: 0.585

For 2s:
Midpt error: 2.834
Euler error: 2.748

For 4s:
Midpt error: 50.070
Euler error: 48.113

Seems that, at least for this function, the Euler method holds up better. Tomorrow, I'll try it with a function where the second derivative isn't always positive on the interval I'm testing.

Hitchhiker 42 23-12-2016 21:53

Re: numerical solution of differential equations
 
2 Attachment(s)
And the new sheets:

Ether 23-12-2016 21:57

Re: numerical solution of differential equations
 
Quote:

Originally Posted by Hitchhiker 42 (Post 1623255)
And the new sheets:

where did you get the revised accel formula?




Hitchhiker 42 24-12-2016 15:22

Re: numerical solution of differential equations
 
Quote:

Originally Posted by Ether (Post 1623256)
where did you get the revised accel formula?




I took the derivative of the actual velocity function. Is this not correct?

GeeTwo 24-12-2016 15:40

Re: numerical solution of differential equations
 
Quote:

Originally Posted by Hitchhiker 42 (Post 1623358)
I took the derivative of the actual velocity function. Is this not correct?

No, as I read it you're setting x''=3x/2. This would be solved by a function of the form x=Ae3x/2

Hitchhiker 42 24-12-2016 16:43

Re: numerical solution of differential equations
 
Quote:

Originally Posted by GeeTwo (Post 1623363)
No, as I read it you're setting x''=3x/2. This would be solved by a function of the form x=Ae3x/2

Could you explain what this means? I'm not sure I understand...

Ether 24-12-2016 17:21

Re: numerical solution of differential equations
 
Quote:

Originally Posted by Hitchhiker 42 (Post 1623377)
Could you explain what this means? I'm not sure I understand...

In post14 you wrote:
Quote:

Originally Posted by Hitchhiker 42 (Post 1623196)
I've attached your spreadsheets modified for 1/4*x^3 + 1.

I am assuming what you actually meant by that is

x(t) = 1/4*t^3 + 1

Is that correct?

If so, then in order to investigate the performance of Euler vs Midpoint numerical solution (in the context of this thread) you need to convert that to an initial value problem (IVP) consisting of a differential equation (involving only x, x', and x'') plus initial values for x(t) and x'(t) at some point t=to.



Hitchhiker 42 24-12-2016 17:39

Re: numerical solution of differential equations
 
Quote:

Originally Posted by Ether (Post 1623380)
In post14 you wrote:


I am assuming what you actually meant by that is

x(t) = 1/4*t^3 + 1

Is that correct?



Yes, sorry about that. That was what I meant.

Ether 24-12-2016 21:04

Re: numerical solution of differential equations
 
1 Attachment(s)
Quote:

Originally Posted by Hitchhiker 42 (Post 1623381)
Yes, sorry about that. That was what I meant.

OK.

x(t) = 1/4*t^3 + 1 is the analytical solution to the Initial Value Problem

a(t) = sqrt(3*v(t))

with initial values*

x(0.01) = 1.00000025

and

v(0.01) = 7.5e-5

As you can see from the spreadsheet, the Midpoint method gives much better results for that IVP than Forward Euler and Forward/Backward Euler.


* selected to avoid the stationary point at t=0


GeeTwo 25-12-2016 04:18

Re: numerical solution of differential equations
 
Quote:

Originally Posted by GeeTwo (Post 1623363)
No, as I read it you're setting x''=3x/2. This would be solved by a function of the form x=Ae3x/2

Quote:

Originally Posted by Hitchhiker 42 (Post 1623377)
Could you explain what this means? I'm not sure I understand...

Sorry, that should have been x''=Ae√3t/√2:o

if x=Ae√3t/√2,
then x'=√3Ae√3t/√2/√2 (chain rule)
and x''=3Ae√3t/√2/2 (chain rule again) = 3x/2.

Edit: I knew there was more to it, and just figured out the other part:

x''=3x/2 ==> x= Ae√3t/√2 + Be-√3t/√2

Ether 25-12-2016 07:50

Re: numerical solution of differential equations
 
Quote:

Originally Posted by Hitchhiker 42 (Post 1623196)
I've attached your spreadsheets modified for 1/4*x^3 + 1

Quote:

Originally Posted by Ether (Post 1623380)
I am assuming what you actually meant by that is

x(t) = 1/4*t^3 + 1

Is that correct?

Quote:

Originally Posted by Hitchhiker 42 (Post 1623381)
Yes, sorry about that. That was what I meant.

Quote:

Originally Posted by Hitchhiker 42 (Post 1623358)
I took the derivative of the actual velocity function. Is this not correct?

Yes, but you got x and t confused.

given:

x(t) = 1/4*t^3 + 1

... take time derivative of x(t) to get:

x'(t) = (3/4)*t^2

...take time derivative of x'(t) to get:

x''(t) = (3/2)*t


Now solve for the differential equation:

solve x'(t) for t:

x'(t) = (3/4)*t^2 => t=sqrt(4x'(t)/3)

... and then substitute for t in x''(t):

x''(t) = (3/2)*t = (3/2)*sqrt(4x'(t)/3) = sqrt(3*x'(t))




Hitchhiker 42 25-12-2016 16:46

Re: numerical solution of differential equations
 
Quote:

Originally Posted by Ether (Post 1623429)
Yes, but you got x and t confused.

given:

x(t) = 1/4*t^3 + 1

... take time derivative of x(t) to get:

x'(t) = (3/4)*t^2

...take time derivative of x'(t) to get:

x''(t) = (3/2)*t


Now solve for the differential equation:

solve x'(t) for t:

x'(t) = (3/4)*t^2 => t=sqrt(4x'(t)/3)

... and then substitute for t in x''(t):

x''(t) = (3/2)*t = (3/2)*sqrt(4x'(t)/3) = sqrt(3*x'(t))




I see... so that column is in terms of x', not t. I've updated the spreadsheet to reflect that and it seems to show that the Euler method does better.
dt = 0.01s, error measured at t=3s.

Euler error: 0.2061
Midpoint error: 5.0828

This, I presume, is for the reason I mentioned in my first post.

Ether 26-12-2016 00:03

Re: numerical solution of differential equations
 
Quote:

Originally Posted by Hitchhiker 42 (Post 1623449)
I see... so that column is in terms of x', not t. I've updated the spreadsheet to reflect that and it seems to show that the Euler method does better.

You're still struggling with this, but I can't point out your error since you didn't post your spreadsheet.

I think you may have overlooked my earlier post #24. The attachment shows how to set up the formulas.

The Midpoint method is clearly better than either Forward/Forward Euler or Forward/Backward Euler for this IVP.



Hitchhiker 42 28-12-2016 22:05

Re: numerical solution of differential equations
 
1 Attachment(s)
I redid the midpoint spreadsheet - now at t=9.96s with dt=0.01s, the error is only 0.96. I replaced the Am column with the Am = sqrt(3*x').

Now to search for a possible explanation...
I did find this http://www.physics.drexel.edu/~steve...rs/simple.html

My guess would be that for this function, which, on the interval being examined, is concave up always (x'' > 0), the Euler method uses a point from farther back than the midpoint method to determine the slope (beginning of the interval slope vs. mid-interval slope). As it's concave up, the Euler method lags behind the midpoint method in growth, and so grows slower than the actual function by more than the midpoint method.

Now to test a method where it uses the end of the interval's slope...

Hitchhiker 42 28-12-2016 22:18

Re: numerical solution of differential equations
 
1 Attachment(s)
Quote:

Originally Posted by Hitchhiker 42 (Post 1623821)
Now to test a method where it uses the end of the interval's slope...

Drat... I tried it using the slope at the end of the interval instead of at the beginning, and it turned out to have a tad bit more error compared to the actual function.


All times are GMT -5. The time now is 08:48.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi