Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
Hello,
Attached is a Mathcad 15 file. It is for incremental/ iterative solution using Newton-Raphson method to trace a nonlinear curve. I am using another example that has a solution. It is enclosed in the sheet.
1. I am unable to plot the curve resulting from Newton-Raphson.
2. i don't know how to plot the graph "number of Iterations" vs. "Increment"
3. I don't know what " While 1" in the attached file mean.
Both solutions are included in the attached file but i am not able to generate them.
Thanks,
Sam
Solved! Go to Solution.
спасибо Vladimir,
@SFares , please see attached.
Now with that correction, and an additional:
You can have your plots:
Success!
Luc
1.2.:Please save your sheet as a Mathcad 11 (.mcd) file and attach, that'll save me a lot of retyping.
3: while 1 means forever. Then there must be another provision to exit that loop: break if .... does that.
Success!
Luc
Here it is.
спасибо Vladimir,
@SFares , please see attached.
Now with that correction, and an additional:
You can have your plots:
Success!
Luc
Thanks a lot Luc! Next time I will keep saving it to Mathcad 11 in mind.
Sam
Hi Luc,
1. In looking at the logic, what is the initial value for "w" =w1 that is used in calculating "Kt",The step right " for i 1..n"?
2. what does cIti=nIt at the bottom do?
For some reason I couldn't paste any pictures.
Thanks
Sam
Hi Sam,
1.
The program starts with:
The first line of the program reserves the full length+1 of the array (by setting the element n+1 to 0) this initializes all other elements of the array to 0. So in effect it defines the array to all zero's.
Then Pa is initialised to 0, and also the cIt array is initialised (by setting its nth element to 0).
Then starts the for loop. The Kt value calculation uses wi, and i starts with 1, so it takes the first element of the w array, which is defined, and has a value of 0 because it was initialised to 0's. The program determines each w value starting the iteration with w=0, simply because that is where w is initialised. Maybe you can speed it up by starting w at the last found value.
2.
The program counts the number of iterations needed for each of the found values in a variable named nIt ("Number of iterations"?). The assignment:
puts the nIt value into the correct position of the array cIt. The way it was written:
would (try to) assign something to the nIt'th element of cIt. But nothing is actually assigned. So the cIt array remains initialised, all zero's. A side effect is that i gets assigned the value of nIt, the number of iterations. Fortunately that doesn't disrupt the loop, because the loop is controlled by the for statement, that sets i to the correct value for the next w-value to deteremine, and this is the last statement in the loop where i is used as an index.
Success!
Luc
Thank you so much,Luc,for your detailed and easy to follow answer. And I also appreciate you for taking the time to do it.
Best regards,
Sam
Hello Luc,
1. In the logic you solved, how does it pick the first value w1 to compute Kt before it start iterations?
2. Is there a way to generate the list of Kt values at the points of convergence when "w" satisfies "f" criteria to stop iterating?
i am not sure if i should've started a new topic
.Thanks,
Sam
Thanks a lot Vladimir!
Unfortunately, I don't have Mathcad 15, only Prime 7, but as far as I can tell ...
1. I am unable to plot the curve resulting from Newton-Raphson.
You need to plot it as a second trace within the plot (also change w's upper limit from -100 to 60). I think in M15, you just need to type a comma after your current arguments and type the second ones. You need -Pp(K2,wNPr) on the y-axis and -wNRr on the x-axis. Change the line type of the first item to a thinner line, and add symbols to the second trace.
2. i don't know how to plot the graph "number of Iterations" vs. "Increment"
First fix the error in your return value. It should read ( clt[i ) <- nlt, not clt[( i<-nlt ).
Then plot cItNR[i (y-axis) against i (x-axis).
3. I don't know what " While 1" in the attached file mean.
As Luc's explained it just means "loop forever". The escape clause is, as Luc guessed, the "break if |f| ..." line.
Cheers,
Stuart
In the attachment you can find Mathcad Prime worksheet and PDF file for preview.
Thanks, Vladimir.
However, I translated the worksheet to Prime 7 and then suggested M11..15 solutions (the same as Luc's, except that I revised the upper limit of w to 60).
Cheers,
Stuart
Thanks a lot ttokoro!
There were a couple of mistakes you made right off the bat:
1. You made the nIt assignment in your program to the index instead of the cIt holder.
2. The w and cIt holders were of different vector sizes.
You can plot all three sets of information on the same plot like I did, or make a separate plot for the Iterations.
As for the while 1, I don't know why it's even there since it will always evaluate to true since 1 is greater that 0 any day of the week. I would have keyed on the iteration parmeter so the program would not have chance keep on iterating beyond some reasonable value, like maybe 10 or 20. I didn't mess with it.
The physical model you are working with is highly non-linear. It almost looks like a break-away control switch. Being a structural engineer myself, I have always worked with real world (linear) stuff. I have always tried to avoid non-linear things unless I have to for stuff like plasticity or high temperature design.
Also, why did you not use unit assignments right away instead of all the cumbersome text units. I telling you from experience, this leads to a lot of avoidable mistakes and misinterpretations. Mathcad does a good job keeping track of units.