Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

MathCAD While Loop

Status
Not open for further replies.

Cockroach

Mechanical
Jan 17, 2003
1,104
I'm trying to get a very simple example started used the Kepler Equation, E = M + e sin E, which is an iterative solution set given M and e as constants.

So I guess E and compute the right hand side, thus generating E' on the left. This would then feed into E on the right and I would recompute E'. Usually I have a set point for loop exit as the difference between E' and E as a neglegibly small number, 0.00001.

I can't understand the syntax to MathCAD14. Any ideas?

Kenneth J Hueston, PEng
Principal
Sturni-Hueston Engineering Inc
Edmonton, Alberta Canada
 
Replies continue below

Recommended for you

Hi Kenneth, you'd be better off in the Mathcad forum. Anyway,

M:21
e:4
E:21 "That's a guess

root( M+e*sin(E)-E,E)=

gives you the normal way of solving it. I'll leave the users of the new improved Mathcad (sarcasm intended) to answer your loops question.



Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
M := something
e := something
E := your guess value

Given

E <CTRL>= M + e*sin(E)

Find(E)=

Unless you're purposely wanting to solve it manually, in which case you'll need to create program loop.

But it's generally more complicated than your sketchup in your OP, since you essentially need to implement Newton's method, and iterate to find a point on the opposite side of the actual solution, and then iterate down to the solution within the tolerance. The selection and variation of step size as you hunt around the solution and close in is relatively non-trivial.

TTFN

FAQ731-376
 
Oh, sorry, didn't explain. The bit at the front is called a Given-Find Solve Block. It's not unlike the Excel Solver, and it iterates on its own to find a solution. Unless you are looking to practice programming, there's generally no need to write your own solver. Greg's approach is likewise a self-iterating algorithm.

TTFN

FAQ731-376
 
In the case of the equation in question there is a bit of a problem with various values of M and e. With appropriate choices there can be anywhere between 0 and infinite roots. So any 'blind' algorithm is going to have to be pretty clever if it is going to find all of them. I'm guessing e is usually -1<e<1, in reality.

IRStuff, is there any advantage in using a Solve block instead of root in this case?

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
root is probably more general purpose, as it has the ability to limit the range of the solution, however, I think that Find allows you a variety of strategies for finding the solution, e.g, Levenberg-Marquant, conjugate gradient, etc.

Ken,

As always, you should plot the function so that you can get a visual on where the solutions should be expected. In Greg's example there are 3 possible solutions, requiring 3 different guess values to find the exact values. Now, that's something you could possibly place into a FOR loop, iterating through different guess values of E to find unique solutions.

TTFN

FAQ731-376
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor