Author |
Message |
|
dubidoo
Newbie
Joined: 22 Apr 2007 Posts: 5
|
Posted: 22 Jun 2007 01:47:38 pm Post subject: |
|
|
Code: (fxy,h,xn,yn,xf)
Func
local k1,k2,k3,k4,ite,xn,yn,i
(xf-xn)/h→ite
For i,1,ite
h*fxy|(x=xn and y=yn)→k1
h*fxy|(x=xn+h/2 and y=yn+k1/2)→k2
h*fxy|(x=xn+h/2 and y=yn+k2/2)→k3
h*fxy|(x=xn+h and y=yn+k3)→k4
yn+(k1+2*k2+2*k3+k4)/6→yn
xn+h*i→xn
EndFor
return yn
EndFunc
"Explaining the code"
This gets an equation for the user, a delta, a initial x value, a initial y value and a final x value.
But the variable xn doesnt comport as i expect, cause i input the following values to the function (2*x*y,0.1,1,1,1.5), we have five iterations and the five xn value is 2.
I try with other values and xn degenerates from 1.2 this is, the program does the first two iterations well.
[s]PD : the strange sign is ->[/s] Fixed. -DarkerLine
Last edited by Guest on 22 Jun 2007 02:15:12 pm; edited 1 time in total |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 22 Jun 2007 02:21:16 pm Post subject: |
|
|
First off, I think you left out an [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]h in the equations for [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]k2, [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]k3, and [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]k4. Those lines should be as follows:
[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]h*fxy|(x=xn+h/2 and y=yn+h*k1/2)→k2
h*fxy|(x=xn+h/2 and y=yn+h*k2/2)→k3
h*fxy|(x=xn+h and y=yn+h*k3)→k4
As for the increment of [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]xn, the line [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]xn+h*i→xn should be merely [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]xn+h→xn (or else you're incrementing [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]xn by one step the first time, two steps the second time, and so forth).
You could also change the loop to [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]For xn,xn,xf,h, and get rid of the incrementing line entirely (as well as the line calculating [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]ite - in fact, the variables [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]ite and [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]i would be unnecessary).
Finally, you don't need to declare [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]xn and [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]yn as local - they already are, by virtue of being parameters.
Last edited by Guest on 22 Jun 2007 02:26:57 pm; edited 1 time in total |
|
Back to top |
|
|
dubidoo
Newbie
Joined: 22 Apr 2007 Posts: 5
|
Posted: 22 Jun 2007 03:39:12 pm Post subject: |
|
|
Thanks.
This is was my first program in my new TI Titanium.
The algoritm is RK4 and is well implemented, no need of h in the y argument
Quote: As for the increment of xn, the line xn+h*i→xn should be merely xn+h→xn (or else you're incrementing xn by one step the first time, two steps the second time, and so forth).
That was the problem. I fix it and now the program runs like a bull :)
Thanks for your help and your time.
I want to put the values x1,y1 in a ite x 1 matrix, this is, each value of x in a single row, how i can do that, i consult my manual and i cant get the function :(
---
Code: (fxy,h,xn,yn,xf)
Func
local k1,k2,k3,k4,ite,sol
(xf-xn)/h→ite
newmat(1,ite)→sol
For i,1,ite
h*fxy|(x=xn and y=yn)→k1
h*fxy|(x=xn+h/2 and y=yn+k1/2)→k2
h*fxy|(x=xn+h/2 and y=yn+k2/2)→k3
h*fxy|(x=xn+h and y=yn+k3)→k4
yn+(k1+2*k2+2*k3+k4)/6→yn
xn+h→xn
yn→sol[i]
EndFor
return sol
EndFunc
The problem gets an error when it executes
Without the matrix stuff the programs works :(
Don't double post. (Terms and Conditions) –Goose
Last edited by Guest on 22 Jun 2007 04:08:53 pm; edited 1 time in total |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 22 Jun 2007 04:04:31 pm Post subject: |
|
|
I think what you want to do is put each *point* of the approximation (i.e. each (xn,yn)) in a row of the matrix, since that is the more interesting return value.
In either case, your problem is that you have to access elements of a matrix not with one coordinate - [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]sol[i] - but with two, the row and the column - [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]sol[i,1]. If you want to be able to use only one coordinate, then a list would be a better choice.
Quote: The algoritm is RK4 and is well implemented, no need of h in the y argument Oh, right, I didn't notice that you'd already multiplied k1..k4 by h when first calculating them. The implementation I looked at did it in the final step
Last edited by Guest on 22 Jun 2007 04:10:46 pm; edited 1 time in total |
|
Back to top |
|
|
dubidoo
Newbie
Joined: 22 Apr 2007 Posts: 5
|
Posted: 22 Jun 2007 04:17:24 pm Post subject: |
|
|
Code: (fxy,h,xn,yn,xf)
Func
local k1,k2,k3,k4,ite,sol
int((xf-xn)/h)ite
newmat(ite,1)sol
ynsol[1,1]
For i,1,ite
h*fxy|(x=xn and y=yn)k1
h*fxy|(x=xn+h/2 and y=yn+k1/2)k2
h*fxy|(x=xn+h/2 and y=yn+k2/2)k3
h*fxy|(x=xn+h and y=yn+k3)k4
yn+(k1+2*k2+2*k3+k4)/6yn
ynsol[i+1,1]
xn+hxn
EndFor
return sol
EndFunc
This is the matrix implementation but i get the error "invalid in a function or current expresion" and the calculator suggest the error near yn->sol[1,1], but i remove that line and the problem continues :(
Sorry for asking a lot and for my bad english. |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 22 Jun 2007 04:20:23 pm Post subject: |
|
|
I think you forgot to make [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]i local? |
|
Back to top |
|
|
|