Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Jacobi method - show all the partial solution of the sys. iteration by iteration
Hello,
I want to out put all the partial solution of the sys. iteration by iteration in a table (or m x n matrix):
itr x1 x2 x3 x4
0 ... ... .... ....
1 .... .... .... ....
- - - - - - - - - - - - - - - - -
itr .... .... .... ....
Also i don't know why in my file does not accept itr->0 instead accept begining from itr->1. I attached the file.
You've set ORIGIN:=1, this means that indexing in arrays and matrices starts at 1, not 0.
Success!
Luc
@tubar wrote:
Also i don't know why in my file does not accept itr->0 instead accept begining from itr->1. I attached the file.
Because you have set ORIGIN to be 1 at the top of your sheet and you use x[itr in your program. itr=0 would mean an invalid array index if ORIGIN=1 and thats exactly what the error messages says.
That one related to the ORIGIN is the minor problem. I take it as it is. Instead, the biggest problem that I still not solved is related to the OUTPUT : iteration vs partial solution of the system. I cannot make the function/file to group all iteration solutions in a table or a matrix. The file is attached in the previous messaje.
It's not clear what you expect as OUTPUT. Please post a picture of what you would like the OUTPUT to be for the illustrated case.
Success!
Luc
The solution, just for the given example from the file should appear like this (in table or matrix format):
I cannot obtain this entire table of partial solutions, I can obtain displayed only the final solutions (1 , -3, 4, 0.5) from the last iteration 15 when it is matched the convergence. For me it is not enough, and I am frustrated to be locked only in a problem of displaying the solution despite the algorithm from there solved the problem.
Finally I obtained the OUTPUT in the way represented in the attached file. If anybody have an additional idea to compact more the algorithm, I am waiting with interest. I attached the file.
Thank you very much for the support. You are cool.
I see you found it.
You have to note: The result of a function is the result of the last statement executed in the function. Generally it is better (programming practice) to use the explicit statement involving 'return' for that. (Note that you cannot type 'return', you have to take it from the programming palet.)
But 'return' can also be used in the middle of a program. basically it causes the program to stop and present the result of its argument.
Here's a very simple example:
Now see what happens if I take away the last statement:
If you end a program with a loop (a for loop in this case) the last statement of the last iteration through the loop is returned as the result. Hope this helps with understanding Mathcad progams.
Success!
Luc
Still exist a problem: while the partial solutions are extracted correctly for displaying, instead the partial errors are extracted bad. I don't know why.
Please, see on the attached file.
Check your mathcad implementation of the jacobi() function against the example (just above your 'correct' picture:
1. The conditions ifor the WHILE loop ar NOT exactly the same.
2. The first statement inside the WHILE loop is different.
3. The last statement of the first FOR loop contains an absolute value. You've swapped the arguments to it. (That should not cause different results)
...
Success
Luc
I found. There was problem in link with how xold read the values of x from the previous cycle of while. So I added a new FOR instruction for reading.
Thank you very much. Now the problem solved exhaustively. I attached the corrected file to be used by others interested.
Something still remains strange in the way Mathcad Works:
1) If I remove from the script ORIGIN:=1 and instead I set from Menu the ORIGIN=1 the algorithm works setting itr-->0. Otherwise, it imposes to set itr--->1. It should not be the same thing? Why the manual setting of ORIGIN affects the program running.
2) it is a way to escape from the intermediary variable e -->err_i so that the matrix of results to read directly the results from err ???
The problem is solved by now, but I want to add some perfection and elegance to the concept of solving.
If you want 'more elegance' and more general usability, you should make your program work independently from the actual value of ORIGIN. For that you have to use the variable ORIGIN in your program, but at the right place.
Here's an example, simple, but it's for demonstration purposes:
The functions vectorsum() and sumvector() both attempt to sum alle elements of the vector supplied in the argument. The answer, 1+2+3=6, is easy.
Since ORIGIN=0 ate the start, vectorsum() fails, because it incorrectly assumes the ORIGIN=1.
Just setting ORIGIN to 1 after the definition of the function doesn't help. The function must be redefined before vectorsum() runs with no error.
As you can see sumvector() is well programmed, it works irrespective of the actual value of ORIGIN.
Note that length() give the length of a vector, in itself that number is '1-based' (starts at 1) so it generally works with an ORIGIN setting of 1.
In general, using ORIGIN and last() cause the least problems when indexing vectors. For matrices the functions rows() and cols() behave similar to length() of a vector. They give the number of rows and columns. So with matrices you'd have to define lastrow() and lastcol() yourself, or work with ORIGIN+rows()-1, and ORIGIN+cols()-1 respectively. Note that while ORIGIN is usually set to either 0 or 1, it can be set to (almost) any number. You could set it to -10, or 100...
Success!
Luc
I appreciate the description of the instruction ORIGIN. However, setting it in the ways:
1) Tools ------> Worksheet options ------> Buil-in variables ------> Array origin (ORIGIN) = 1
2) Just writing ORIGIN:=1 in the code that overlap ORIGIN=0 by default from Menu.
the behavior of the processed algorithm is different when I set particularly for this code itr--->1. This is the main contradiction that I can get through of it but I cannot explain it.
I get the very same error when itr is set to 0 in the program, regardless if ORIGIN is set to 1 via the menu or explicitly with ORIGIN:=1.
Maybe you forgot to delete an ORIGIN:=0 statement in your sheet? This would overrule the ORIGIN setting in the menu beginning from the position in the sheet where it is positioned.
Yes, indeed, in the last file where the algorithm is well refined does not make the difference the choose ORIGIN related to itr. I think there were a conjunction of problems in the first file that I shared in the first message, a file that now is superseded.
Thanks.
From intermediary variable e_i if I would escape, it will be cool. I want just to express ee_itr,m ---> err_m instead to create intermediary variable e_i<----err then ee_itr,m ---> e_m . It is somehow too indirect the actual path with intermediary variable.
I got it !!! Yeeeep. I had to write ee_itr,m ---> err , so err without to be err_m in order to be displayed the solution. The intermediary and non-necessary variable e or e_i is now removed.
Thank you very much for the Socratic disposition of debate. It conducted to the truth.
Now, my file is perfect with minimal instructions. I attached it.