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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

output of odesolve

prop_design
15-Moonstone

output of odesolve

is there a way to convert the odesolve output to a matrix, so that the max and min can be found. apparently the odesolve output is a function. i attached a worksheet. i want to convert t and x to matrices.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:prop_design)


@prop_design wrote:

is there a way to convert the odesolve output to a matrix, so that the max and min can be found. apparently the odesolve output is a function. i attached a worksheet. i want to convert t and x to matrices.


How about

Werner_E_0-1618902721650.png

Of course you could use any vector "tvec" as long as its elements are all in the range from 0 to tmax. You may simply replace tstep by any other value.

 

 

View solution in original post

18 REPLIES 18
Werner_E
25-Diamond I
(To:prop_design)


@prop_design wrote:

is there a way to convert the odesolve output to a matrix, so that the max and min can be found. apparently the odesolve output is a function. i attached a worksheet. i want to convert t and x to matrices.


How about

Werner_E_0-1618902721650.png

Of course you could use any vector "tvec" as long as its elements are all in the range from 0 to tmax. You may simply replace tstep by any other value.

 

 

prop_design
15-Moonstone
(To:Werner_E)

thanks werner,

 

i had been trying to use vectorize but it wasn't working for me. i'll try again. i must have been missing something.

Before there was ODEsolve there were the line solvers, (Adams, rkfixed, Rkadapt, Bulstoer, and Radau).

 

rkfixed et al are still there, and the output is the matrix you're looking for.

 

ODEsolve automated one of the line solvers and fit a curve to the points.

 
 
 
 
 
 
 
 
 
 
 
 
 
 
0

thanks fred,

 

i remember those days. i remember keeping up with the changes in the solvers. i don't recall the output differences though. i'm forgetting a lot. i actually like the odesolve output though. having it be a function makes some things a lot easier. but then you need to convert it, which had me stuck. thanks to werner for unsticking me. the state space output is in a matrix and it seems like the last column of the matrix is velocity. however, it doesn't match up with the velocity you get using the time and displacement output. so i'm still confused there. but all of my other questions were answered by forum users. so many thanks to all. i have the examples posted. i have been updating them a lot and updating the post.

hi fred,

 

i did further work on the examples and found some interesting things that relate to what you mentioned. it may be better to use the older solvers. taking derivatives of the odesolve function output is very slow and causes some error to show up. also the derivatives are working badly. sometimes you have to take the second derivative of displacement because the first derivative of velocity won't solve. other times you have to do the opposite. it is much faster and less error to manually calculate velocity, kinetic energy, and acceleration manually from matrix output. also the reaction force calculations. i converted the state space matrix output to a function and took derivatives as another test. it displayed the same problems. so the issue is definitely with the derivatives and not the solvers.

ttokoro
20-Turquoise
(To:prop_design)

Electric circuit analysis of the same system.

 

prop_design
15-Moonstone
(To:ttokoro)

hi,

 

this is interesting. is there any way you could provide something similar in a MC15 file.

LucMeekes
23-Emerald III
(To:prop_design)

In Mathcad 15 it can be done even better.

First let me refer you to: https://community.ptc.com/t5/PTC-Mathcad/Toolbox-Solving-Ordinary-Differential-Equations-symbolically/m-p/689336

From there you fetch LODEsolve.xmcd

Then you can use the file attached here. Note that the file is written in Mathcad 11, so with Mathcad 15 you may see the symbolic output differently formatted, which may require you to move regions, in order for them to be separated. Then you can enjoy.

 

Success!

Luc

thanks luc,

 

i'll take a look at this. much appreciated. i've been noticing some problems with all of the numerical solvers in MC15. There are random errors popping up in different spots depending on the solver. None of them seem capable. The errors are hard to spot visually, but i've started to get good at finding them. So it's now become important to look into the symbolic solution instead. unfortunately, that's something i have almost no experience with.

hi luc,

 

i've been looking over the various files you mentioned. i'm afraid i can't figure out how to call the solver. i attached a MC15 file, but i'm not sure if you can open it. I think you are using MC11. i attached a picture as well.

 

ideally, i'd like to use three different forcing functions. cosine wave, sine wave, and square wave. i'd like to be able to change the damping ratio and other parameters as well. to operate in different regions. i'm not sure if your solver cares which region you are in or not. so stuff like beats, resonance, under damped, over damped, critically damped.

 

question on how to use.png

LucMeekes
23-Emerald III
(To:prop_design)

Note that LODEsolve is a SYMBOLIC ONLY function, it does not evaluate numerically. But of course, as with any symobilic expression, you can assign its result to a function and evaluate that numerically.  You almost did that in your MCAD15 file: xsym(t):=LODEsolve(ODE,f(t),init,x,t).

The one thing you forgot was the symbolic evaluation, so it should be:

xsym(t):=LODEsolve(ODE,f(t),init,x,t) ->

(That is, press [CTL >] at the en of the expression.)

 

1. How did the file operate in Mathcad 15, that I attached specific to your problem (The file LM_20210429...)?

2. The LODEsolve() function should function with the first two of your proposed f(t), not with the third.

The reason for that is that the symbolic processor cannot handle the mod() function. You'll have to create a square wave using the heaviside step function.

 

As for functional properties of the ODE (whether or not damped, critical or whatever): The LODEsolve() function does not care. It executes a pure mathematical operation (an automation of what ttokoro showed) that, if the ODE meets the requirements for it, and a solution can be found, will produce the solution. And if you work with a pure symbolic expression you get a pure symbolic mathematical function.

 

I've elaborated your example here:

LucMeekes_5-1619770237097.png

gives:

LucMeekes_6-1619770265994.png

 

Note that the expression runs out to the right for a couple of pages. In Mathcad 15 it may look differently, due to another symbolic processor.

Now we can use the (result) function xsym:

LucMeekes_1-1619769730734.png

and plot the results over time

LucMeekes_2-1619769780245.png

Note that the Mathcad built-in odesolve function produces apparently the same result.

LucMeekes_3-1619769899953.png

But it's not EXACTLY the same, if I subtract the ODEsolve result from the LODEsolve result:

LucMeekes_4-1619769978456.png

With the very same xsym() function you can now experiment with different values of b, m, k and omega.f.

And you can easily calculate differentials:

LucMeekes_0-1619787756466.png

The Mathcad file is attached.

 

Success!

Luc

 

thanks luc,

 

the example you sent worked in mc15. i just didn't fully understand how to use it. the attachment you just sent also works. i only had to add a simplify command to the acceleration result, to remove a warning it was showing. i'll try to figure out how to do a square wave. not sure if i will be able to or not.

 

yeah, having worked with the numerical solvers for the last few days, i see they are having unexplainable problems. odesolve looks to be mostly boundary issues. state space is weirder. it's ok at the boundaries but inboard seems to randomly go haywire. so that's what got me interested in trying a symbolic solution. some examples i have seen the growing error that you showed. it seems to depend on inputs. the attachment you just sent might have different inputs than your pic. the error isn't growing in mc15 but oscillating. not a big deal, i have seen error like in your picture before.

LucMeekes
23-Emerald III
(To:prop_design)

The warning on the acceleration function probably deals with it 'being too large to display'. That should be no problem, you still can work with it. Once you start to work with square waves that are symbolically acceptable you will see that warning more often. Note that you can still work with the (symbolic) result, even if it cannot be displayed.

Regarding square waves: See if this helps for you. It's not finished, some things don't work to my satisfaction in Mathcad 11. But they may work in Mathcad 15, and be of use to you.

 

Success!
Luc

thanks a lot. i got the cosine and sine waves working. your example helped me see what i was doing wrong with calling your function. i have to run errands for awhile. but i'll check out the square wave when i get back.

 

edit; yes, that is what the warning was.

hi luc,

 

this was very helpful. i have been messing with it, so that i can use it in my previous examples. i attached a mc15 and mc11 version. i didn't realize i could save files as mc11. not sure if you can open either of them. working with this made me notice that some of my previous work may have had an error. i updated some of my formulas. however, i have a lot more work to do, to integrate everything. i'll post them on the other thread, when i get them done.

 

anthony

hi luc,

 

it looks like your custom solver won't accept the square wave with all the extra input variables.

 

edit; attached is a mc11 file showing the issue. looking at your custom solver, it looks like it wants f to have 3 inputs. the square wave has a lot more inputs than that.

LucMeekes
23-Emerald III
(To:prop_design)

The first response I get from the f3 function in your files is:

LucMeekes_0-1619987348495.png

This is due to the fact that the numeric processor doesn't know x, and complains.

I had explained that LODEsolve is a symbolic-only function. You always have to evaluate it symbolically.

After I've added a symbolic evaluation I get this:

LucMeekes_1-1619987512262.png

This is due to the fact that the number of cycles is unknown. While the symbolic processor in general can deal with unknown variables, the number of cycles is used by the pulse function in a summation operator. Well, in this case the symbolic processor would like to know how many summations there are. So we can help it by telling. I define nc before using LODEsolve in this definition, and I delete nc from the parameter list of xsym3, gives:

LucMeekes_2-1619988638833.png

(This expression continues for several pages)

But it can be used. A bit further down you've plotted f3, I put xsym3 along:

LucMeekes_3-1619988733266.png

.

Now I'll be the first to admit that working symbolically with square wave signals isn't ideal.

I've found no way to define a continuous square wave signal that is acceptable to the symbolic processor.

(With sines and cosines it's easy, they are already known symbolically).

You can define a continuous symmetric square wave as:

LucMeekes_4-1619988974450.png

but when evaluated symbolically it becomes:

LucMeekes_5-1619989003575.png

which leads to a Laplace transform of:

LucMeekes_6-1619989041358.png

And that's not what we wanted.

A continuous asymmetric square wave can be defined with:

LucMeekes_7-1619989161575.png

But:

LucMeekes_8-1619989266098.png

So far the only square wave definition that works symbolically, and is Laplace transformable is one that is defined in terms of the Heaviside step functio:

LucMeekes_10-1619989554243.png

But then you have to define every pulse individually, which can be automated using the summation operator:

LucMeekes_11-1619989773908.png

but not out to infinity:

LucMeekes_12-1619990180532.png

So square waves can be used symbolically with a limited number of cycles.

Here's a setup that works (at least in Mathcad 11):

LucMeekes_13-1619990337802.png

(Again, the expressions above are huge).

LucMeekes_14-1619990432464.png

Mathcad 11 file is attached.

 

Success!
Luc

 

P.S. Be advised that the symbolic process doesn't "know" about units. It doesn't "know" how to convert them etc. like the numeric processor does. At best, it treats them like unknown variables, and if you are careful you can have them cancel out if necessary.

If you want to work with symbolics and units, preferrably first use the symbolics to arrive at a function (with parameters for all your variables that need to carry units) that the numerical processor understands, then call that function with the united variables as parameters. So instead of:

LucMeekes_0-1619991010365.png

(Note that you do not get t in seconds!)

do:

LucMeekes_1-1619991046030.png

 

 

 

thanks luc,

 

when i open your file in mc15, the xsym definition says 'cannot understand this syntax'.

 

note; i didn't have the symbolic evaluation on for xsym3 because it just hangs in mc15.

 

i notice one other thing that might be important. on your custom solver. if i turn on automatic calculation for it, a number of errors show up, within the file. so maybe there is a mc11 to mc15 issue there. it's all way too complex for me to understand. i think i'm just going to abandon the symbolic solve. from what i got for the cosine and sine wave, there was little difference. it did help me find a problem with odesolve. it wasn't running out to the correct tmax. it was short by tstep. i followed the help, but the help wasn't working the way the actual solver is. so i changed one input to odesolve and got the solver to work as expected. so before, the help for state space was messed up. now i find the help for odesolve is messed up too. i think we are having some problems of mc11 to mc15 that are going to make this a nightmare. but i appreciate all the help you provided.

Announcements

Top Tags