Community Tip - You can change your system assigned username to something more personal in your community settings. X
Fixed-Point Iteration for nonlinear systems of equations - my Mathcad alghoritm doesn't work
Hello,
I try to make my Mathcad alghoritm to work for a nonlinear system by using Fixed-Point Iteration . Unfortunately still I cannot get the results. Something is missing in my script. I attached my Mathcad file.
The results whould look finally like this (I obtained it in Excel in order to compare the results if possible):
It xold yold x y errx erry errf10 errf20
-----------------------------------------------
1 2.0000 4.0000 1.4142 6.0828 0.5858 2.0828 0.6023 23.7569
2 1.4142 6.0828 1.6132 7.3348 0.1990 1.2520 3.2299 9.4517
3 1.6132 7.3348 2.4150 6.9238 0.8018 0.4109 4.8888 38.8502
4 2.4150 6.9238 3.2743 5.6438 0.8593 1.2800 1.7585 28.6511
5 3.2743 5.6438 3.5326 4.8065 0.2583 0.8373 1.5000 6.8054
6 3.5326 4.8065 3.3135 4.6017 0.2191 0.2048 1.7316 4.4348
7 3.3135 4.6017 3.0410 4.7449 0.2725 0.1432 0.8185 6.2781
8 3.0410 4.7449 2.9034 4.9577 0.1377 0.2128 0.0356 3.5969
9 2.9034 4.9577 2.8972 5.0811 0.0061 0.1234 0.3272 0.2816
10 2.8972 5.0811 2.9532 5.0907 0.0559 0.0096 0.3124 1.4396
11 2.9532 5.0907 3.0056 5.0425 0.0524 0.0481 0.1223 1.3810
12 3.0056 5.0425 3.0258 4.9968 0.0203 0.0458 0.0363 0.5519
13 3.0258 4.9968 3.0198 4.9785 0.0060 0.0183 0.0852 0.1304
14 3.0198 4.9785 3.0057 4.9828 0.0141 0.0043 0.0574 0.3554
15 3.0057 4.9828 2.9962 4.9947 0.0096 0.0119 0.0121 0.2503
16 2.9962 4.9947 2.9941 5.0030 0.0020 0.0084 0.0149 0.0590
17 2.9941 5.0030 2.9966 5.0050 0.0025 0.0020 0.0184 0.0604
18 2.9966 5.0050 2.9997 5.0030 0.0031 0.0020 0.0093 0.0786
19 2.9997 5.0030 3.0012 5.0004 0.0015 0.0026 0.0001 0.0413
20 3.0012 5.0004 3.0012 4.9990 0.0000 0.0014 0.0042 0.0008
21 3.0012 4.9990 3.0005 4.9990 0.0007 0.0000 0.0036 0.0176
In C++ not problem ! I run the file with DevC++ and also Codeblocks. It just did the job.
Thats because the C program uses the data type "long double" and your compilers support it accordingly. The actual size of a variable of that type may differ depending on the implementation in the compiler. As far as I am aware GCC uses 16 bytes but VC++ for example uses the very same 8 byte as it uses for a simple "double" variable - so no improvemet in VC++ if you switch from double to long double.
Even if a compiler stores a long double in 16 Bytes, it may still decide to just use the 80-bit extended precision type which the hardware (x86 architecture) supports natively (even though 10 bytes would suffice, 12 or 16 bytes may be used to maintain data structure. But the compiler may also use the 128-bit quadruple precision format. There usually is a compiler switch to turn off the 80-bit mode.
In conclusion: As long as we don't know the used compiler quite well and the comiler switches set for compilation, we cannot say much about the precision by just looking at the source code.
Mathcads variables in numeric mode use the data type "double" as defined in the standard IEEE 754-1985. Depending on conversion round-off errors its said that you may expect a precision of about 1e-14. But of course depending on the actual situation you may also have luck with 1e-15 or even 1e-16. You simply should not rely on it 😉
The symbolic engine in Mathcad provides much higher precision but calculation time will become significantly longer and you may also run into other problems using it.
Here is a small example showing the effect of round-off/conversion errors in Mathcad. You may implement it in C and look at the differences when using different data types.
You may also play around with the symbolics by changing the 1 into 1.0 in just one of the two functions. then change it in both. Using a floating point number like 1.0 forces the symbolic into a numeric float mode. You may also do this by adding the modifier "float" in the symbolic evaluation. You may control the precision by adding the number of significant digits to use (default is 10, I think) by typing "float,100" for example.
But it is possible to tune Mathcad Symbolic to expand longer expressions? About 10 years ago I made a research on QUINTIC EQUATION that it is known still dowsn't have an analytic solution from mathematicians.
And I found a big, big, Mathcad limitation that objectively does not have a powerful justification because it is about DISPLAYING 100-200 serial terms, and not about calculation precision. The displaying left to right should not be a fact to limit the researcher. I think this frustrating limitation still exists also in Mathcad Prime 5, 6.
At least if it is possible to double the actual capacity of displaying (expanding) the large expressions... For the software designer should not be a big difficulty, just impose a bigger memory allocation for displaying....
The symbolic error "The symbolic result returned is too large to display ..." sure is an annoyance. Only way to get rid of it is if you somehow can get your hand on a Mathcad 11 implementation which uses Maple internally. MC11 is considered by many as the best Mathcad version ever - at least it uses the best symbolic engine compared to later versions. But even if you succed in obtaining a version of MC11 you would not be able to license it (legally) as PTC had already turned off the necessary license servers.
If you look what PTC had done with its "development" of Prime and consider that real Mathcad is not developed any further, it looks like you have to live with that limitation of not being able to see longer symbolic results.
BTW, sometimes its possible to get to see the desired results using some tricks:
Do you know Werner why this Newton Interpolation instead to obtain 6.3125 it gives 6.359 ? I sketched on paper, but I dont find any mistake in the writing the equations in Mathcad.
I got it finally from a book.
I was in trouble by complicating the equations. Now I escaped using a more simple approach :). Too many equations bring troubles.
Glad you found the error (the unnecessary loop) yourself. In your new version you never use prod1 and prod2, so you may delete their initialization.
According the calculation of the Newton coefficients, here is a shorter way to do it without if..otherwise:
"Mathcad 11 implementation which uses Maple internally"
It's not the fact that Mathcad 11 uses Maple, but it knows an environment variable that you can set/change to control the size of symbolic display.
I currently have NODE_DISPLAY_LIMIT set to 0x80000 (524288 decimal).
Examples:
...
(and just as easily):
...
Luc
Cool . How You did that NODE_DISPLAY_LIMIT set to 0x80000 (524288 decimal). . In which file from Program Files of the Application ?
I think Mathcad 13 is also very capable, it was able to support some long expression. Since Mathcad 14 I didn't understand the politics of PTC, I participated several times as voluntary tester to their new platforms, I gave to them feedbacks but they still didn't implemented the necessary corrections. Mostly they were interested only on BUGS.... bugs, bugs, bugs....Bugs Bunny. Not creative proposals.
Due to the limiting of displaying long expressions, I had to stop several initiatives of research. Symbolic calculus often is essential. And sometimes only a paper and a pen is not enough.
It's a feature only supported for Mathcad 11. It supposedly does NOT work for any version later than Mathcad 11, and I seem to remember that it also does NOT work for any earlier versions... As Werner indicated: Mathcad 11 is the best ever.
Given that Mathcad 12 and 13 still use Maple as symbolic processor the feature is not tied to the symbolic processor. Other than that it's an undocumented feature that I learned from a rep a very long time ago. If you search this forum you may be able to find some posts about it. But, as said, unless you have Mathcad 11, it's of no use to you.
You could try and persuade PTC to build support for display of larger symbolic results into a future version of Prime, but be careful what you wish for:
Being able to display large results requires Mathcad to handle those large graphics. In Mathcad 11 it comes at the price of becoming slow, to sometimes unresponsive, and occasionally crash.
With (any version of) Prime being much slower than Mathcad 11 in ALL respects, you may be better off with not being to display larger results...
If you really need to work with symbolics heavily, consider using Maple, or Mathematica. Note that they're not nearly as intuitive to work with as Mathcad, but you need to choose the right tool for the job, considering all aspects. Then Maple or Mathematica may be a better choice for you.
Success!
Luc
Its nice that the algorithm can be switched on symbolic calculation (by removing some initial numeric values) so it generates the formula. For example, I obtained the generated Polynomial.
I didn't know that the Programming Functions was working with the Symbolic Tool Calculation.
Allways in Mathcad a function that is used in the main code (algorithm) should be written before the algorithm ?
For example, C++ tolerates to put a function on beginning or at the end of the code, and Matlab requires to put the defined functions always at the end.
It is possible to use or define GLOBAL VARIABLES inside an ALGHORITM such that you can call it when you are outside of that ALGHORITM that already has its specific output result ?
I can call somehow a vector x(i)=A+... inside an ALGHORITM , take its results from there, and after that to use that vector outside not depending on what defined output has that ALGHOIRTM ?
The only way that a Mathcad program can change a worksheet variable is if you assign the result(s) of the program to that variable.
Werner, I invite you to cooperate in my book as co-author among other collaborators that help me to finalize that book ""Numerical methods with programming in C++, Matlab and Mathcad"". Around a common flowchart there are issued approx. equivalent codes in C++, Matlab and Mathcad.
The book is now about 70% completed.and initially will be in my national language. Based on its initial feedbacks will be completed later a more substantial version in English. I am the coordinator of the book, and other 5-6 co-authors help me specifically for several aspects to finish it.
So, are you interested? Your large experience with Mathcad will help me to perfect it. The only task you will have will be the review of my existing mathcad files and transmit feedbacks, just only feedbacks. So, your spent time on that will be minimal.
Can't take additional tasks at the time but I'm around here in the forum on a regular basis if you have specific questions.
Hello Tubar, from :
It seems like this :
Combining :
Best Regards.
Loi Le