cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Nonlinear Incremental/ Iterative solution Newton-Raphson

SFares
12-Amethyst

Nonlinear Incremental/ Iterative solution Newton-Raphson

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

1 ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:VladimirN)

спасибо Vladimir,

 

@SFares , please see attached.

LucMeekes_2-1630052244463.png

Now with that correction, and an additional:

LucMeekes_3-1630052283915.png

You can have your plots:

 

LucMeekes_0-1630052184621.png

LucMeekes_1-1630052197228.png

 

 

Success!
Luc

View solution in original post

16 REPLIES 16
LucMeekes
23-Emerald III
(To:SFares)

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.

LucMeekes
23-Emerald III
(To:VladimirN)

спасибо Vladimir,

 

@SFares , please see attached.

LucMeekes_2-1630052244463.png

Now with that correction, and an additional:

LucMeekes_3-1630052283915.png

You can have your plots:

 

LucMeekes_0-1630052184621.png

LucMeekes_1-1630052197228.png

 

 

Success!
Luc

SFares
12-Amethyst
(To:LucMeekes)

Thanks a lot Luc! Next time I will keep saving it to Mathcad 11 in mind.

 

Sam

SFares
12-Amethyst
(To:LucMeekes)

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

 

LucMeekes
23-Emerald III
(To:SFares)

Hi Sam,

1.

The program starts with:

LucMeekes_0-1630229279360.png

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:

LucMeekes_1-1630229799084.png

puts the nIt value into the correct position of the array cIt. The way it was written:

LucMeekes_2-1630230139285.png

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

SFares
12-Amethyst
(To:LucMeekes)

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

SFares
12-Amethyst
(To:LucMeekes)

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

 

 

SFares_1-1630203691352.png

 

.Thanks,

Sam

 

 

SFares
12-Amethyst
(To:VladimirN)

Thanks a lot Vladimir!

StuartBruff
23-Emerald II
(To:SFares)

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.

StuartBruff
23-Emerald II
(To:VladimirN)

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

ttokoro
20-Turquoise
(To:SFares)

image.png

 

SFares
12-Amethyst
(To:ttokoro)

Thanks a lot ttokoro!

ttokoro
20-Turquoise
(To:SFares)

image.pngimage.pngimage.pngimage.png

Structures_401
6-Contributor
(To:SFares)

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.

Top Tags