
Like (0)
I am a beginner with programming in Mathcad. I am having trouble understanding how to use FOR Loops to dump results to a matrix from which I can extract values to plot in a graph. I wish to solve a nonlinear equation and evaluate this function for a range of values and then graph the results in the form of a Bifurcation Diagram. The nonlinear equation becomes chaotic at certain input force values.
I have constructed a Runge Kutta 4th order function to integrate the equation and develop the displacement and velocity time waveforms  no problem. As a first step I want to evaluate the equation for a range of forces and store the velocity (Y2) versus time (Y0) waveforms in a matrix. As a second stage I want to sample the velocity waveform after it has stabilised (after say 100 cycles) at periopdic intervals to see if the velocity amplitude remains stable or whether a chaotic behaviour occurs.
The attached Mathcad file has the integration front end and my attempt at a nested FOR loop to index the force amplitude and store the velocity (Y2) values in a matrix. The matrix output only seems to store the last iteration. I would appreciate if someone could get me over this first hurdle to evaluate all velocity waveforms for the range of forces 'A".
Extracting data to a new matrix after every N1 data points would be the next step and then plotting this data as aBifurcation Diagram.
Any assiatnce would be appreciated.
Cheers
Ross
You had the assignment to Xi,j in the wrong place.
Alan
Alan,
Thankyou for your fast response. That was embarassingly easy to fix. I guess I am still somewhat confused with the syntax for nesting these FOR loops.If you are aware of an online reference that provides more on the topic than just the tutorial I would be keen to check it out. Thanks again
Some example can be found in the attachment (it's include material from "Mathcad Help" [hotkey F1]).
The attached might of of help.
Mike
Good example, Mike. From which ebook this are?
There from 'Inside Mathcad  Programming'.
Mike
Thanks. It seems that I missed one: "Inside Mathcad Series: Programming, Solving, and ODE Solvers"
That is actually different to the one I was talking about.
Mike
What you mean?
The Ebook I was referring to was soley about Programming, ODE Solvers.
Mike
In case you might be interested, I've attached an alternative solution method using Mathcad's builtin ODE solver (at the end of the attached file). There seems little point in reinventing the wheel by programming your own integration routines (except for educational reasons).
Alan
Message was edited by: Alan Tidied up the graph.
Alan, Mike & Vladimir,
Many thanks for your multiple responses. The tutes and ebook extracts provide valuable demos. I appreciate your generousity in spending time educating the "beginners".The ODE solver is a very elegant means of solving this problem. Its amazing how much calculation can be generated with so few lines of program code.
Cheers Ross
You're welcome.
Yes, the ODE solver is a very elegant way of solving the problem, but I must admit that I have found it the most difficult to get my head around.
Mike
Alan,
I have been tinkering with a program that includes your ODEsolve suggestion it is very effeicient!
I am trying to include a nonlinear backlash (flatspot) into the displacement variable. As I understand the ODE solve block only allows first derivative experssions on LHS. Is there a way I can include a function thant modifies x(t) that includes the backlash  it is included in the attached sheet as g(t) just above the solve block.
Any ideas would be greatly appreciated.
Cheers
ross
Ross Emslie wrote:
Alan,
I have been tinkering with a program that includes your ODEsolve suggestion it is very effeicient!
I am trying to include a nonlinear backlash (flatspot) into the displacement variable. As I understand the ODE solve block only allows first derivative experssions on LHS. Is there a way I can include a function thant modifies x(t) that includes the backlash  it is included in the attached sheet as g(t) just above the solve block.
Any ideas would be greatly appreciated.
Cheers
ross
Something like this?
Alan
Alan,
Thanks yet again.I didn't believe it could be that simple!This forum certainly allows you to push new boundaries.
I will keep tinkering.
Cheers
ross
Alan,
If I could burden you just once more!
I have taken your odesolve method that outputs the vector xv(A) and the final step in solving my problem is to introduce a second degree of freedom with another 2nd order equation.
I have increased the vector from 2x1 to 4x1 to output the extra displacement and velocity variables (see attached)but there is now an error I don't know how to eliminate. From other programs I have seen there does not seem to be a restriction as to how many variables can be solved for in the odesolve block  so can you advise what the problem might be in my solveblock.
Thanks
Ross
Ross Emslie wrote:
Alan,
If I could burden you just once more!
I have taken your odesolve method that outputs the vector xv(A) and the final step in solving my problem is to introduce a second degree of freedom with another 2nd order equation.
I have increased the vector from 2x1 to 4x1 to output the extra displacement and velocity variables (see attached)but there is now an error I don't know how to eliminate. ...
The equations work in principle, but the solutions grow extremely rapidly, so the system crashes before your endtime. The attached shows they work over a shorter period. However, I wonder if the ODE's are formulated correctly as the solutions basically explode!
Alan
Alan,
Thanks. At least I had the right idea. Debugging programs is a nightmare for the learner! I will track through the equation derivations and check all my constants. I'll let you know what I find.
Cheers
ross
Ross Emslie wrote:
... I will track through the equation derivations and check all my constants. ...
Also check carefully the signs of all the terms in dv/dt and du/dt.
Alan
Alan,
I have found a couple of constants that were incorrect. The program now gives reasonable looking time waveforms so I now can undertake some sensitivity studies to explore the problem further.
Many thanks again for your assistance. Let me know if you are ever in Sydney and I'll buy you a beer!
Cheers
Ross
Alan,
I continue to tinker with this problem and after debugging the last version of the program I have been getting sensible answers. I have now made the problem incrementally more compliacted by adding an addditional 2 degrees of freedom to my system of ODE's.
Whilst keeping essentially the same structure as your solve block I am now getting an error for N1 stating it needs to be a vector  I cannot fathom why. Any suggestions would be apprectaied.
Cheers
ross
Ross Emslie wrote:
Alan,
I continue to tinker with this problem and after debugging the last version of the program I have been getting sensible answers. I have now made the problem incrementally more compliacted by adding an addditional 2 degrees of freedom to my system of ODE's.
Whilst keeping essentially the same structure as your solve block I am now getting an error for N1 stating it needs to be a vector  I cannot fathom why. Any suggestions would be apprectaied.
Cheers
ross
You enter the loop with N as a vector, but change it within the loop into a matrix (N_{i,j}), hence the complaint about it (no longer) being a vector.
Stuart
Stuart and Alan,
Many thanks guys for highlighting what, in hindsight, is now an obvious and very poor choice for a matrix name. I can now move forward to explore the chaos (double meaning!) in my nonlinear problem.
Cheers
Ross
Stuart is correct. You are trying to construct a matirx N, forgetting that you already have a vector N. Since the matrix is being constructed within a loop involving N, Mathcad is getting confused! Rename the matrix N to, say, NN and all is well  see attached.
Alan