Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.maple > #354 > unrolled thread
| Started by | pluton <plutonesque@gmail.com> |
|---|---|
| First post | 2012-02-08 00:02 -0800 |
| Last post | 2012-02-08 11:58 -0800 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.soft-sys.math.maple
strange behavior in a while loop pluton <plutonesque@gmail.com> - 2012-02-08 00:02 -0800
Re: strange behavior in a while loop acer <maple@rogers.com> - 2012-02-08 00:37 -0800
Re: strange behavior in a while loop pluton <plutonesque@gmail.com> - 2012-02-08 11:58 -0800
| From | pluton <plutonesque@gmail.com> |
|---|---|
| Date | 2012-02-08 00:02 -0800 |
| Subject | strange behavior in a while loop |
| Message-ID | <16524289.30.1328688155956.JavaMail.geo-discussion-forums@yqik15> |
Hi,
I have the following code for a fixed point iteration in two dimensions:
Restart; with(linalg);
Gt:=matrix(2,1,[2-2*x2,1/2*sqrt((2-x1)*(2+x1))]);
#Maple command to get a vector as a function of x1 and x2;
G:=array@op@unapply([op](eval(Gt)),x1,x2):
# initial quantities
X0:=matrix(2,1,[0.5,0.5]);epsilon:=1e-12;Nor:=2;i:=1;
# loop
while Nor > epsilon do
X1:=G(X0[1,1],X0[2,1]);
Y:=evalm(X1-X0);
N:=evalm(transpose(Y)&*(Y));
Nor:=evalf(sqrt(N[1,1]));
X0:=X1;
i:=i+1;
end do:
If you run this, you'll see that from the second iteration, X0 and X1 are identical and I do not know why? It means that when X1:=G(X0[1,1],X0[2,1]); is performed (in loop 2) X0 gets the value of X1 right away and Y is then 0 and the procedure stops while it should not. I think there is some kind of a tricky thing happening inside Maple (13) but I am not sure what. I'd be happy to have your insight. Thanks
[toc] | [next] | [standalone]
| From | acer <maple@rogers.com> |
|---|---|
| Date | 2012-02-08 00:37 -0800 |
| Message-ID | <27739495.3020.1328690221255.JavaMail.geo-discussion-forums@yqkz3> |
| In reply to | #354 |
Try replacing the line inside the loop which updates X0 to instead be, X0:=evalm(X1); You probably want that, for X0 to be a copy of X1 and thereafter be distinct from X1. That is, you want X1 to not be identical to X1 even after any subsequent change in the value of X1. The motivation is that the code assigns X1-X0 to Y. And that would always produce scalar 0 after the unfortunate X0:=X1, no matter how X1 changed. acer
[toc] | [prev] | [next] | [standalone]
| From | pluton <plutonesque@gmail.com> |
|---|---|
| Date | 2012-02-08 11:58 -0800 |
| Message-ID | <1509663.1.1328731090311.JavaMail.geo-discussion-forums@vbbha3> |
| In reply to | #356 |
Thank you for your answer. I found a way to solve this problem by avoiding the use of the linalg bank and by using LinearAlgebra instead. I'll try your suggestion very soon
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.maple
csiph-web