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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

BE. How to better translate this matlab code into Mathcad Prime implementation?

Cornel
18-Opal

BE. How to better translate this matlab code into Mathcad Prime implementation?

Hi,
I have this matlab code and I want to translate it to Mathcad Prime. I tried below one way, but maybe someone can implement better.
Matlab:

Cornel_4-1716797345678.png


Mathcad Prime 9:

Cornel_5-1716797359262.png

Cornel_6-1716797376291.png


And if I remove evaluation of t, the the plot does not work anymore:

Cornel_7-1716797469212.png

And then how to make this difference/calculation:

Cornel_0-1716797666610.png

Cornel_1-1716797705955.png

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:Cornel)

Using inline evaluation after defining the range t is an undocumented trick to turn the range into a vector. Thats the reason it does not work if you omit this evaluation. This trick also does not work anymore in Prime 10, so you should create the vector in a different way (see the screenshot below and the attached file).

V1 is a vector with 501 elements, but the vector V2 you create has 502 elements! Thats the reason why V1-V2 does not work. You have to take care of the number of times the loop runs and also note that you use ORIGIN=0 in your sheet, so the first vector index is 0, not 1.

Werner_E_0-1716802765506.png

But as you are working in Mathcad/Prime, so why aren't you using units? You may also consider using "Odesolve" instead of programming your own numeric approximation.

Werner_E_1-1716803150782.png

 

 

View solution in original post

5 REPLIES 5
Werner_E
24-Ruby V
(To:Cornel)

Using inline evaluation after defining the range t is an undocumented trick to turn the range into a vector. Thats the reason it does not work if you omit this evaluation. This trick also does not work anymore in Prime 10, so you should create the vector in a different way (see the screenshot below and the attached file).

V1 is a vector with 501 elements, but the vector V2 you create has 502 elements! Thats the reason why V1-V2 does not work. You have to take care of the number of times the loop runs and also note that you use ORIGIN=0 in your sheet, so the first vector index is 0, not 1.

Werner_E_0-1716802765506.png

But as you are working in Mathcad/Prime, so why aren't you using units? You may also consider using "Odesolve" instead of programming your own numeric approximation.

Werner_E_1-1716803150782.png

 

 

How to find also the maximum peak values for V1 and V2, and the coresponding time at which these maximum values occure?
Cornel_0-1716803749496.png

 

Werner_E
24-Ruby V
(To:Cornel)


@Cornel wrote:

How to find also the maximum peak values for V1 and V2, and the coresponding time at which these maximum values occure?


You should have no problems finding the maxima of the pure sine wave V1, don't you? 😉

 

According V2 - if you decide for the functional approach as shown before, you may use the "root" function in one of its flavors to see where the first derivative is zero.

Werner_E_0-1716806071222.png

 

Using the array approach you may use "lookup" with all its drawbacks (was discussed quite some times here in the forum, last thread about the problems was BUG: inconsequent behaviour of match() function

Werner_E_1-1716806768251.png

 

 

And this? Value and time at that lowest part/point.

Cornel_0-1716810003704.png

 

Werner_E
24-Ruby V
(To:Cornel)

Werner_E_2-1716811634373.png

 

Werner_E_0-1716811509199.png

 

Top Tags