Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
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:
Mathcad Prime 9:
And if I remove evaluation of t, the the plot does not work anymore:
And then how to make this difference/calculation:
Solved! Go to Solution.
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.
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.
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.
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.
How to find also the maximum peak values for V1 and V2, and the coresponding time at which these maximum values occure?
@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.
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
And this? Value and time at that lowest part/point.