Skip to main content
19-Tanzanite
April 20, 2021
Solved

Matlab Code to Mathcad (15) - FE

  • April 20, 2021
  • 2 replies
  • 5689 views

Hello,

Can someone help me with this?

I want to translate some Matlab code into Mathcad 15.

 

CornelBejan_0-1618949224485.png


Thanks.

Best answer by Werner_E

I couldn't help trying it myself 😉

Here is a method without using F and yext and without using matrix/vector operation which does the full 250001 points calculation in less than one second. I made Tsim an argument of the function and added prec (aka precision) as its last argument. prec is responsible for the time step width h = Ts / prec. So prec=200 gives you the result from your Matlab screenshot. lower values result in a larger step width and less precision. With the new function you may also try prec=400 (resulting in 500001 points) without having to wait long for the result.

 

Werner_E_2-1619040121718.png

 

Guess I was wrong with respect to the plot points limit. This seems only apply when plotting a function over a range. When plotting one vector over the other, this limit seems not to apply as I also could plot vectors with more than 2 millions points.

I ran into a strange effect  (presumably round off errors when i tried to calculate the next time value using (i+1)*h. The values of iL were far off compared to the values calculated with the other methods (which resemble better the result of the MatLab calculation). Compare the two by changing the appropriate line in the program and decide yourself which result you may trust more - actually I am not really sure about it.

Here are the results which seem to match the Matlab results:

Werner_E_4-1619040246952.png

 

 

 

 

2 replies

21-Topaz II
April 21, 2021

Hi,

Nearly there just have to get the last variable "vo" sorted.  Must take a break to do something else.

Put in an iteration limit so easier to work with file.  Put in a trace on "i" to see the number of iterations in the debug window.

Here it is at 20000 iterations.  Confident "iL" and "vcout" are correct.

Capture.JPG

Cheers

Terry

21-Topaz II
April 21, 2021

Hi,

Finished file.  Have set the iteration number to 5.   The iteration number defines the number of plot points.  There is a limit in Prime to the number of points, much lower than Matlab.  In the example provided you will run out of plotting ability far before 12e-3 time limit.  It takes 25000 iterations for 1.25e-3.

 

View the debug window and set debugging and you can see how long it takes to get to the iteration limit set.

 

Capture.JPG

 

Cheers

Terry

Cornel19-TanzaniteAuthor
19-Tanzanite
April 21, 2021

Thanks.

For:

CornelBejan_2-1618997324356.png

 

CornelBejan_1-1618997309528.png

 

But it takes a long time to calculate and display the graphs ...
This is not very nice if you have to wait a few minutes for 1-2 graphs in the context of a simulation time quite short of a few milliseconds (for example 15-20 mili seconds)...
It would have been nice if it went faster and easier because if I put some graphs to calculate and display and for a relatively reasonable simulation time then my Mathcad will explode:)) ...

But anyway, thanks.

Cornel19-TanzaniteAuthor
19-Tanzanite
April 21, 2021

@LucMeekes@Werner_E 

Do you have any idea???