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

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

Working with results from the Mathcad State Space ODE Solver

afalzone
1-Newbie

Working with results from the Mathcad State Space ODE Solver

Hi,

I usually work with range variables. I don't know how to work with the results from the Mathcad State Space ODE Solver. They are in a matrix. I want to subtract the results from the state space solver from results of a calculation using range variables. Moreover, I calculated displacement using range variables and want to compare that to the displacement calculated with the state space solver. Some sort of conversion is needed but I can't figure it out.

Thanks for your help.

Update 1; I found one work around but it's pretty brutal. You can't seem to do derivatives on vectors. So I had to brute force things a bit too much for my taste. Hopefully, the experts here will have better ideas. I updated the attachments to this post.

Update 2; I figured it out. I used what I learned from the 'problem (2)' file and applied that to the updated 'problem (1)' file. Much more elegant fix.

11 REPLIES 11

Hi Anthony,

Have you tried to use the built-in "submatrix(...)" function?

Thanks Vladamir,

I have never really worked with matrices in Mathcad before, so I wasn't aware of the feature you mentioned. I will check it out. It seems like I have to work with range variables to do the derivatives and matrices to use the state space solver. So somehow working with both looks like it is going to be a necessity. I did figure out a way to do what I needed, but I still wonder what the best way to work with both is.

How about this:

hmm,

that is strange. you are getting an incorrect result with that method. I looked into it but can't find were it is going wrong. I think the method I used is getting a correct result.

you are getting an incorrect result with that method

Really? Why do you think so?

I just streamlined what you did.

The right plot differs of course because there I plot the error over t, not over the indices.

R

the magnitude of your plots is way higher than it should be. if you inspect the two columns being subtracted you can see they are basically the same. there is also a plot, of the two columns of data, that shows the difference between them is very small. i'm not sure why the answer you computed is coming out that way that it is. i don't really know how to work with matrices very well. i happened upon something that worked but know very little about it. i still wonder the best way to intermix matrices and calculations with range variables. it seems like Mathcad requires both for different things.

Ooops, I see. I forgot to vectorize the call of your function s() (its called with vector t as argument).

RichardJ
19-Tanzanite
(To:afalzone)

i still wonder the best way to intermix matrices and calculations with range variables. it seems like Mathcad requires both for different things.

You only need range variables for one thing: indexing a vector, in which case the range takes only integer values. Sometimes range variables are also the easiest way to define the abscissa values for a plot. My recommendation is that you in fact never use them for anything else. That is what you have done in your "problem(2)" worksheet, where the only range variable is n. This is the best approach. When you have vectors you do not always need to index them using a range variable to use them, although you may need to use the vectorize operator. For example, by default the product of two vectors is the scalar product, so if you want element by element multiplication then you need to vectorize the expression. A vectorized multiplication is much faster than a multiplication done using range variable indexing, so this is the preferred approach. Also, when plotting a vector against a vector, you do not need to index using a range variable. If you just provide the names of the vectors Mathcad knows what you want.

Richard Jackson wrote:

You only need range variables for one thing: indexing a vector, in which case the range takes only integer values. Sometimes range variables are also the easiest way to define the abscissa values for a plot. My recommendation is that you in fact never use them for anything else.

Not even in for-loops?

RichardJ
19-Tanzanite
(To:Werner_E)

Not even in for-loops?

Semantics perhaps, but I don't normally think of a for-loop variable in a program as a range variable, although of course in practice it is (albeit it one local to the program).

Top Tags