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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

How to speed up calculation/plotting time when dealing with derivative?

Cornel
19-Tanzanite

How to speed up calculation/plotting time when dealing with derivative?

Hi,

How to speed up calculation/plotting/update time for vL1(t)?
Try changing for example value of R1 from 1 to 2, and compare the time needed for the two graphs to update each other.
vL1(t) plot will take longer to update than iC1(t) and vC1(t) plot. There are some ways to reduce calculation/plotting time for vL1(t)? Or what is the reason of why vL1(t) take much longer time to calculate/plot/update than iC1(t) and vC1(t) calculate/plot/update plot time?

Cornel_1-1717082964827.png

Cornel_0-1717082449079.png

ACCEPTED SOLUTION

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

A rather coarse timing of parts of the sheet can be achieved using the time() function as you sure have seen already often in this forum. It is not overly accurate, though, and I would only use it with multithreading switched off.

 

But in the case of the function you initially asked for you should not need a program as you can surely see the difference "with free eye".

 

In the attached sheet I compare the calculation speed of your original definition of v.L1, my approach using the second derivative and then my last attempt with the solve block. The results are quite clear.

Werner_E_0-1717097616544.png

 

View solution in original post

13 REPLIES 13
Werner_E
25-Diamond I
(To:Cornel)

A simple way to speed up the calculation of v.L1 is to define that function as being the second derivative of v.C1

Werner_E_0-1717085909000.png

 

Werner_E
25-Diamond I
(To:Werner_E)

Here is an even speedier approach.
I don't like the idea of making the solve block more complicated as necessary but on the other hand this allows us to completely avoid the more time-consuming numerical differentiation.

Cornel
19-Tanzanite
(To:Werner_E)

Do You know a program that calculates how long it takes to odesolve block to make/finish the itself block calculation and then how long it takes to the plot to plot/show the graphs?

Werner_E
25-Diamond I
(To:Cornel)

A rather coarse timing of parts of the sheet can be achieved using the time() function as you sure have seen already often in this forum. It is not overly accurate, though, and I would only use it with multithreading switched off.

 

But in the case of the function you initially asked for you should not need a program as you can surely see the difference "with free eye".

 

In the attached sheet I compare the calculation speed of your original definition of v.L1, my approach using the second derivative and then my last attempt with the solve block. The results are quite clear.

Werner_E_0-1717097616544.png

 

Cornel
19-Tanzanite
(To:Werner_E)

Hm, look at this Werner in the case of integral:

Cornel_0-1717139520502.png

 

Cornel
19-Tanzanite
(To:Cornel)

I found also something strange or at least interesting:

With first variant:

Cornel_5-1717141804782.png

 

Cornel_1-1717141590735.png

 

 

With second variant:

Cornel_6-1717141817726.png

Cornel_4-1717141694910.png
Two different answers...

Cornel
19-Tanzanite
(To:Cornel)

I see that this second variant is more better than the first one, but I do not have any explanation as they seems to be almost the same calculation...maybe the initial condition of ic1(0) and vL1(0) to have an influence here?

Cornel_0-1717142184239.png

 

Cornel
19-Tanzanite
(To:Cornel)

On the other hand: look at vL1(t) plot

With first variant:

Cornel_0-1717143470209.png

Cornel_1-1717143478847.png

With second variant:

Cornel_2-1717143496614.png

Cornel
19-Tanzanite
(To:Cornel)

Though I think I will stay with first variant, and only I will put in the end as below to have more rapidly calculation/plotting:

Cornel_0-1717144099377.png

 

But anyway, its pretty good also like that. Thank you @Werner_E 

Werner_E
25-Diamond I
(To:Cornel)

I don't see what you think that is not OK with the second variant

Werner_E_2-1717198591055.png

 

But of course you should use whatever fits your needs

ttokoro
20-Turquoise
(To:Cornel)

Use t not tend.

image.png

Werner_E
25-Diamond I
(To:Cornel)


@Cornel wrote:

I found also something strange or at least interesting:

Thats very strange, indeed. I would call it a bug. If you set t.end to 1.2 ms or higher  instead of 1 ms you get what seems to me the correct result and not just a constant function.

 

You may consider reporting this to PTC support.

Werner_E
25-Diamond I
(To:Cornel)

Not sure what you want to show with that picture.

If its just that the second one takes too long and the third one fails, then ts one more reason to use the first approach 😉

The reason why the last one fails is similar to the one explained here: Re: How to show all values of this variable?

Werner_E_0-1717196503924.png

 

I also wonder why you are trying to plot a constant function (horizontal line). The definite integral would be evaluated for every single t-value used in the plot ant thats very time consuming for the last two methods.

Or did you mean

Werner_E_1-1717196684644.png

 

 

Announcements

Top Tags