recursive formula in Geogebra-Script possible?
Doing the decomposition of a tridiagonal matrix in to LU the following resursive procedure have to be calculated (a and c are given Lists of dimension n):
1) v_1=2
2) l_k=a_k/v_{k-1}
3) v_k=2-l_k*c_{k-1} k=2 ... n
OK - you can substute 2) in 3) but it does not help either: 4) v_k=2-(a_k/v_{k-1}) *c_{k-1}
The only way I've found is extremly error prone and uses side effects (SetValue) - so you can't use it for a custom tool (my goal)
1) I create a List v with only 2's and copy it to freeObject (so it is alterable)
2) Create a custom tool nextV(<List>a,<List>c,<List>v,<Number>k) which will be invoked with k=2 ...n
3) Alter List v in successive way:
Execute(Sequence("SetValue(v,"+k+",nextV(a,c,v,"+k+"))",k,2,Length(v))
As I said above - it uses side effects, so you cannot use it for a custom tool AND do not
show up in construction protocol - nobody knows what happened.
I thought of spreadsheet - there the recursive formulas above are easy to implement - BUT
how can you fill in formulas in the spreadsheet cells WITH Geogebra-Script?
(Of course its easy in Javascript(no tool possible), ore use invert(Matrix) - algorithm do not use
the special matrix here and therefore is MUCH slower!)
Has anybody solved a similar problem? Any clues?
Thanx for thinking about it
Hi Angsüsser!
Hmm, here my ideas:
You say, that a and c are given lists of dimension n.
4) v_k=2-(a_k/v_{k-1}) *c_{k-1} , k=2,...,n
You can simplify 4) to:
5) v_k=2-(a_k*c_{k-1})/v_{k-1}, k=2,...,n
You can calculate directly a list d of dimension n-1 by the given lists a and c.
d = (list a (without the first element)) * (list c (without the last element))
The factor in 5): (a_k*c_{k-1}) = d_{k-1} , k=2,...,n
And so I think you can get v_k by:
6) v_k = 2 - d_{k-1}/v_{k-1} , k=2,...,n
and that, I hope, should be managed by a simple Sequence-Command, because v_1=2.
Kind regards
mire2
@mire2
6) v_k = 2 - d_{k-1}/v_{k-1} , k=2,...,n
and that, I hope, should be managed by a simple Sequence-Command, because v_1=2.
As I see it - there is no such hope. Sequence-Command assumes that ALL List-Elements of the right hand side of equation 6) are already known - that is not the case here (--> Sequence-Command cannot be used for recursion).
But thanx for thinking about it!
Hi, maybe something like :
maybe the command IterationList() can help.
IterationList( <Expression>, <Variables>, <Start Values>, <Count> )
Its possible to replace <Expression> by a Customer-Tool
its also possibele that <Variables> is a list (in a list)
So you can use the command in the following form:
IterationList( ToolName(L), L, {<list>}, <Count> )
(The output of ToolName(L) must be a list in the same structure as (the list) L
Note: the correct count of {} in the 3. Parameter <Start Values> is important
Ok, another idea with spreadsheet.
You can fill list d described in my first post in the first column A and in B1 you sign in the number 2.
Then you fill B2:
and copy and paste B2 the column down as far as you need it and then, so I hope, you will find in this column B your needed v_k.
Hmm, if this doesn't work maybe a crack gets an idea how to manage this.
Kind regards
mire2
@mire2
As I described in my first post - this is the natural way to do this interactive in a spreadsheet - BUT you can not script this!
Of course it works - only you cannot use it for a custom tool!
"maybe a crack gets an idea how to manage this" - its name is Michel Iroir
@Michel
It's ingenious to use the y-coordinate of a point for the index - I have to admit this idea never come into my mind!
Can you explain why one can use a(k) in Zip to access the List-Element but not in IterationList :
The substitution does NOT work! But that's not important anyway - I am only interested.
Question can be tagged as "Answered"
@ALL
Thank you guys that YOU are thinking about MY problem. Thanx
he pensado mucho sobre este tema y hay aspectos como el orden en que se deben realizar las instrucciones que no están del todo claros y que pueden llevar al mal funcionamiento de las rutinas que se usen. Pero creo que en situaciones simples, donde las instrucciones se realizan con rapidez una vez se comienzan los scripts, es posible sin mucha dificultad programar repeticiones sujetas a condiciones del tipo repeat while o repeat until. En el fondo todas son lo mismo. He programado un par de scripts ( en realidad uno con un motor a) que se ejecutan hasta que se cumple una condición. el script genera una lista de números hasta alcanzar el valor 1. se entiende que si no se alcanzase dicho valor el script acabaría congelando el sistema porque llenaría la memoria. hay que tener cuidado de no entrar en un bucle infinito como siempre.
https://www.geogebra.org/m/KkEtPhRn
si encuentran inconvenientes agradeceria lo comunicaran para ir mejorando la rutina
Comments have been locked on this page!