FAQ  •  Login

Matlab HW6

<<

ME451Vaidyanathan

ME451 Student
ME451 Student

Posts: 8

Joined: Thu Oct 28, 2010 11:49 am

Unread post Mon Dec 06, 2010 10:36 am

Matlab HW6

Hello Prof. Dan

In prob 4 you say:

"If everything works well, you should see a straight line
with slope 1.0 for Forward Euler, and slope 4.0 for Runge-Kutta"

1. For Forward Euler - we use Runge-kUtta as the exact solution.. If so, What should we use for runge-kutta?
2. As far as I understand error should be norm(ycalc - yexact) (where ycalc and yexact are calculated and actual solution vectors). But in the hw you are asking us to compute the error only at a specific instant of time. Can you please clarify as why we are computing the error only at one point (at t = 1.5?)
(I understand that the length of the vectors (ycalc and yexact) are different  - but I am not sure if this is the right method to calculate the degree of accuracy of a numerical method)

Thanks & Regards
Vaidy
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Mon Dec 06, 2010 12:42 pm

Re: Matlab HW6

ME451Vaidyanathan wrote:Hello Prof. Dan

In prob 4 you say:

"If everything works well, you should see a straight line
with slope 1.0 for Forward Euler, and slope 4.0 for Runge-Kutta"

1. For Forward Euler - we use Runge-kUtta as the exact solution.. If so, What should we use for runge-kutta?
2. As far as I understand error should be norm(ycalc - yexact) (where ycalc and yexact are calculated and actual solution vectors). But in the hw you are asking us to compute the error only at a specific instant of time. Can you please clarify as why we are computing the error only at one point (at t = 1.5?)
(I understand that the length of the vectors (ycalc and yexact) are different  - but I am not sure if this is the right method to calculate the degree of accuracy of a numerical method)

Thanks & Regards
Vaidy



1. as stated in the assignment, the reference solution is "faked" by taking for it the solution obtained with RK45 when run with the tiny step-size.  This is because you don't have enough significant digits on your computer to generate a better solution anyways.  this is a standard way of doing things when carrying this type of analysis.

2. this is the way people report the error.  They look at the end of the simulation to see how large the error is.  Again, for this you need the exact solution, which you [almost] never do for any serious IVP.  So you generate a solution with a high accuracy method using a tiny step size and then consider that to be the "exact" or "reference" solution.  Keep in mind that typically the error grows with the length of the interval over which you carry out integration (accumulation of error).  So that's why you want to look at the end of your time interval.
Another way to do this is to look at the norm infinity for the error, that is, to consider the largest error over the entire interval.  this is equally good, except that now you should save the entire reference solution.  given that you integrated with a small step size, this means a lot of data.  In our approach, for the reference solution you only save the last point, at T_end.

I hope this helps.  we can talk more in class tomorrow.
Dan
<<

Wa'el

ME451 Student
ME451 Student

Posts: 7

Joined: Thu Oct 28, 2010 11:46 am

Location: Mifflin

Unread post Fri Dec 10, 2010 2:33 pm

Re: Matlab HW6

question:

so when I'm computing the psuedo exact result using the runge-kutta method, should I be using a bigger range for t (from 0 to 1.5) or is it just that I'm going to use a very small time-step?

I ask because when I'm plotting y vs t, it doesn't look like I'm converging even with a t = 0:0.0001:1.5 .... or should it?

thanks in advance,
Bob Dylan is God
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Fri Dec 10, 2010 4:10 pm

Re: Matlab HW6

Wa'el wrote:question:

so when I'm computing the psuedo exact result using the runge-kutta method, should I be using a bigger range for t (from 0 to 1.5) or is it just that I'm going to use a very small time-step?

I ask because when I'm plotting y vs t, it doesn't look like I'm converging even with a t = 0:0.0001:1.5 .... or should it?

thanks in advance,




Wa'el - you should use RK from 0 to 1.5.  Even with 0.1 the results should actually look really good.  If you consider h=0.01 you practically obtain an approximation of the solution that is within machine precision. 
To conclude, i believe that you have a small bug in your code, for h=0.0001 the results should look really good...
Dan
<<

Wa'el

ME451 Student
ME451 Student

Posts: 7

Joined: Thu Oct 28, 2010 11:46 am

Location: Mifflin

Unread post Fri Dec 10, 2010 6:42 pm

Re: Matlab HW6

Prof:

By "the result will look good" you mean converged to the correct answer?

Thanks,
Wa'el
Bob Dylan is God
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Sat Dec 11, 2010 9:46 am

Re: Matlab HW6

Wa'el wrote:Prof:

By "the result will look good" you mean converged to the correct answer?

Thanks,
Wa'el


Wa'el - yes, that's what i mean.  Except that i would not call it "converged to the correct answer" because "convergence" has (in my mind) the meaning that you try a sequence of things and you see that the results approach something (converge to something).
Here you only try, for instance, h=0.001, and the numerical solution is very close to the actual solution (granted, here you don't quite know what the "actual" solution means since you don't have the analytical solution).

I have this tendency of taking a simple thing and making it complicated.  I hope i didn't confuse you more (than i usually do).
Dan
<<

Wa'el

ME451 Student
ME451 Student

Posts: 7

Joined: Thu Oct 28, 2010 11:46 am

Location: Mifflin

Unread post Sat Dec 11, 2010 10:24 am

Re: Matlab HW6

no actually that clears things up! ... one last question however:

would that solution change if I set my t=0:0.001:10 rather than t=0:0.001:1.5 ?
or is that solution just for t = 1.5sec and it just gets closer to the exact at t = 1.5 using a smaller time step (h=0.001) ?

Thanks for all the help professor!
Wa'el
Bob Dylan is God
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Sat Dec 11, 2010 10:46 am

Re: Matlab HW6

Wa'el wrote:no actually that clears things up! ... one last question however:

would that solution change if I set my t=0:0.001:10 rather than t=0:0.001:1.5 ?
or is that solution just for t = 1.5sec and it just gets closer to the exact at t = 1.5 using a smaller time step (h=0.001) ?

Thanks for all the help professor!
Wa'el


No, that isn't anything special about 1.5.  If you take T_end=273 (pick your favorite positive number here), you should still get the same straight line of slope 4.  There will be one difference though: the longer the simulation, the more error you accumulated.  So while you'll still get a straight line, it will be shifted up, towards larger error values.  What i'm saying is that if you take T_end=273, you should see larger errors, but as you reduce the step-size h, you should see the same tendency of cutting the error.  For RK, if you cut h by 2, the error should be cut by a factor of 16.  Now this error is going to be larger for T_end=273 than for T_end=1.5, but the trend will be the same and captured by the straight line with slope 4.

If you also understand what i'm saying here, stop by, you deserve some M&Ms.
Dan
<<

Wa'el

ME451 Student
ME451 Student

Posts: 7

Joined: Thu Oct 28, 2010 11:46 am

Location: Mifflin

Unread post Sat Dec 11, 2010 8:17 pm

Re: Matlab HW6

got it!
I was actually confused because I thought that y_exact@t=1.5 should equal y_exact@t=300

thanks professor,
Wa'el
Bob Dylan is God

Return to ME451 Fall 2010: Kinematics and Dynamics of Machine Systems

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software.