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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Translate the entire conversation x

defined integral-time

IsFunction
4-Participant

defined integral-time

I do not become a result for the following simple calculation:
Knowns: a function with calculated elements; a plot with t is possible.
(:= (@FUNCTION (@LABEL VARIABLE jerk_MH_N) (@ARGS (@LABEL VARIABLE t))) (@MATRIX 40 1 0.82 0.82 (@NEG 1.64) 6.613 (@NEG 25.687) (@NEG 4.449) 43.482 (@NEG 19.04) (@NEG 16.3) 33.51 (@NEG 18.033) (@NEG 11.234) 13.115 8.629 2.223 (@NEG 17.522) 18.01 (@NEG 4.664) 0.645 2.084 (@NEG 8.107) (@NEG 20.383) (@NEG 10.943) 15.175 (@NEG 0.777) 38.662 (@NEG 3.435) (@NEG 25.798) 6.918 (@NEG 1.875) 0.583 (@NEG 0.458) 1.25 (@NEG 4.542) 16.917 (@NEG 13.272) (@NEG 13.684) 18.154 (@NEG 9.077) (@NEG 9.077)))

weeks t:
(:= (@LABEL VARIABLE t) (@MATRIX 40 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39))

To solve is this defined integral:
(@EQ (@APPLY (@LABEL VARIABLE PA_jerk_MH_N) (@ARGS (@LABEL VARIABLE t))) (@INTEGRAL 0 t (@APPLY (@LABEL VARIABLE jerk_MH_N) (@ARGS t)) t))

t -is unknown!
I tried with t:=0..39
t up at the integral remain red, unknown.
I have standing this problem with the t at any other calculations for ex. at the numeric trapez rules too.

What make I wrong in MP10?

Can me somebody help?


ACCEPTED SOLUTION

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

OK, by now you should have learned two things:

1) Don't copy math expressions from a Prime sheet to your community post here - it gets unreadable

2) Its nice to post pictures, but the worksheet itself would be of much more value most of the time. So use the option to attach files here:

Werner_E_0-1752584864577.png

You stated which version of Prime you are using and that's good an necessary. Next time you may want to do this even more eye-catching at the front of your post.

 

According your Prime problem: You defined a function for jerk and the value you assign is a vector with 40 elements.

That means that the result value for any argument t of your function would be that whole vector. Obviously that's nothing Prime would be able to integrate - hence the error message you receive.

 

You have two options:

1) Use the trapezoid rule but work with the vectors of time and jerk values, not any functions:

Werner_E_1-1752585072846.png

 

2) Turn your data vectors into a function. The most obvious way is to use linear interpolation and Prime offers this out of the box with the function "linterp".

Werner_E_2-1752585198723.png

 

You may also use cubic spline interpolation which also offered by Prime, but I guess that this would not be appropriate in your case. Spline interpolations tends to a more "wavy" (sometimes overshooting), but smoother signal. It may have its use if you intend to use the derivative as it avoids the jumps in the derivative you otherwise get because of the sudden changes in slope.

Werner_E_3-1752585392804.png

Here you see the difference concerning the derivative. But while smother you have to be aware that cubic spline interpolation adds data information which actually is not there in the original data ...

Werner_E_4-1752585743337.png

 

Prime 10 worksheet attached

 

View solution in original post

10 REPLIES 10
LucMeekes
23-Emerald IV
(To:IsFunction)

You should better attach the worksheet file, the .mcdx file.

 

Other than that. Your jerk_MH_N(t) is not a function, but a vector, and you cannot integrate a vector, but you can sum it:

LucMeekes_0-1752581072076.png

And you can construct a curve through your datapoints, using linear interpolation or splines make that into a function and then integrate over that function.

 

Success!
Luc

IsFunction
4-Participant
(To:LucMeekes)

many thanks for your prompt answer.
I tried with linterp bc. this do not modify the amplitude of function but cspl or pspl do this.
I have problems with t as one-ceil-matrix everywhere. How can I transform it in vector, or array with scalar values or as matrix with one ceil, or to function? With jerk_linterp_MH_N(t):=linterp(dates, jerk_MH_N(t), t), and I tried to integrate
integral | t 0 (jerk_linterp_MH_N(t)) and t on the integral is red. The function, or vector jerk_linterp_MH_N(t) is a saw-teeth function in the plot.
I tried with t:=0..39 
The same problem: t on the integral remain red.
At the trapez rules I have with t the same proble: is red in every formulas.

IsFunction
4-Participant
(To:LucMeekes)

I am new here.
Annexed the worksheet file. Maybe you can help me.
I have had the same problems at the derivations d/dt and I changed to numerical formulas.
Werner send me a solution but I need not a scalar as result. I need a function, or matrix with 1 ceil. If I write the integral of Werner integral | time 0 (jerk_fun dt  than I become the message "this value must be real". Or for symbolic resolution I become "Floating error".

Werner_E
25-Diamond I
(To:IsFunction)

OK, by now you should have learned two things:

1) Don't copy math expressions from a Prime sheet to your community post here - it gets unreadable

2) Its nice to post pictures, but the worksheet itself would be of much more value most of the time. So use the option to attach files here:

Werner_E_0-1752584864577.png

You stated which version of Prime you are using and that's good an necessary. Next time you may want to do this even more eye-catching at the front of your post.

 

According your Prime problem: You defined a function for jerk and the value you assign is a vector with 40 elements.

That means that the result value for any argument t of your function would be that whole vector. Obviously that's nothing Prime would be able to integrate - hence the error message you receive.

 

You have two options:

1) Use the trapezoid rule but work with the vectors of time and jerk values, not any functions:

Werner_E_1-1752585072846.png

 

2) Turn your data vectors into a function. The most obvious way is to use linear interpolation and Prime offers this out of the box with the function "linterp".

Werner_E_2-1752585198723.png

 

You may also use cubic spline interpolation which also offered by Prime, but I guess that this would not be appropriate in your case. Spline interpolations tends to a more "wavy" (sometimes overshooting), but smoother signal. It may have its use if you intend to use the derivative as it avoids the jumps in the derivative you otherwise get because of the sudden changes in slope.

Werner_E_3-1752585392804.png

Here you see the difference concerning the derivative. But while smother you have to be aware that cubic spline interpolation adds data information which actually is not there in the original data ...

Werner_E_4-1752585743337.png

 

Prime 10 worksheet attached

 

IsFunction
4-Participant
(To:Werner_E)

Many thanks Werner for the answer.
I attached now a small mcdx file, with short comments in them.
I have had the same problems at the derivations d/dt and I changed to numerical formulas. I think now through 3.th derivation of PM to become jerk I have multiplied the small errors. As difference between for ex. PV_MH_N(t) and PV_jerk_MH_N(t) is not more interpretable.
Maybe you have again time for me!
Thanks in advance!


Werner_E
25-Diamond I
(To:IsFunction)

Your sheet isn't showing any derivatives but a lot of errors we already fixed in my previous answer!

 

jerk_MH_N is a vector, so don't define it as if it were a function.

Werner_E_0-1752765216364.png

 

Not sure what you tried when you evaluated jerk_fun_MH_N(t). t is a vector of just 40 values, so you get a result vector with the 40 corresponding values which should be exact the vector jerk_MH_N.

Werner_E_1-1752765617025.png

So to see the smoothing effect of the spline interpolation you would rather define a range (just for plotting!) with a much smaller step size:

Werner_E_2-1752765706739.png

Next problem:

Werner_E_3-1752765806788.png

1) "time" is a vector with 40 integer values (its the same as vector t). The limit of an integral can't be a vector, it has to be a scalar

2) interpolation is a numeric only process. You can't symbolically evaluate an expression which uses a function derived by numeric evaluation

 

Maybe you meant

Werner_E_4-1752766199596.png

This defines a function which can be (numerically) evaluated at any position

Werner_E_5-1752766260625.png

or plotted, if you like

Werner_E_6-1752766299979.png

 

 

 

 

 

IsFunction
4-Participant
(To:Werner_E)

Many, many thanks Werner for your patience to me!
Now I understand when and how is to vectorise. I integrated 3 times in series the jerk_MH_N matrix with discrete values, I made correct the interp-cspine and I have now analytical results after 3 integration. The last integration was running about 15 minutes.
I think about now how is to filter out the eventually existent noises.
Again many thanks!!!

Werner_E
25-Diamond I
(To:IsFunction)

Calculating 40 values takes 15 minutes? So I would suggest you don't try to plot the last integration function because this would mean evaluating it at much more than 40 positions.

By all your calculations you should never forget that all are just based on 40 discrete input values, which is not really a lot.

 

BTW, you can speed up the calculation significally if you predefine the vector which is the first argument when calling "interp". That way this vector must not be calculated from anew every time the function is evaluated:

Werner_E_0-1752869050979.png

 

IsFunction
4-Participant
(To:Werner_E)

Hallo Werner
Many thanks for your answer.
I have had succes with
vec_s:=cspline(time,jerk_MH_N)
jerk_func_MH_N(t):=linterp(time,vec_s,t)
PA_jerk_MH_N(t):=intergral | t 0 (jerk_func_MH_N(t)) dt
But at each integration level I was pressed to write again these smooth functions.
vec_s_PA:=cspline(time,PA_jerk_MH_N)
PA_jerk_func_MH_N(t):=linterp(time,vec_s_PA,t)
PV_jerk_MH_N(t):=intergral | t 0 (PA_jerk_func_MH_N(t)) dt
and again the same algorithm for PM_jerk
vec_s_PV:=cspline(time,PV_jerk_MH_N)
PV_jerk_func_MH_N(t):=linterp(time,vec_s,t)
PM_jerk_MH_N(t):=intergral | t 0 (PV_jerk_func_MH_N(t)) dt

But all these smoothing's has has delivered wrong results.
If I do not introduce these smoothing's I do not become any analytical results.
Is too simple to set the integral between 0 and 39. These deliver prompt results but the results are not the same as between  0 and t.
I am now to try the trapeze rules for numerical integration.
Did have the MP10 any numerical function for trapeze, Simpson or other integration numerical formulas?

Have a nice day

Werner_E
25-Diamond I
(To:IsFunction)

I am now to try the trapeze rules for numerical integration.
Did have the MP10 any numerical function for trapeze, Simpson or other integration numerical formulas?

I guess that the numerical integration in Prime is using kind of a modified Simpson or the like.

But of course you can't expect any analytical, symbolical results from numerical methods.

So if you use linear interpolation you should get 'exact' results as with the trapezoid rule.

Keep in mind that numerical integration may take a long time.

This is especially true when it comes to plotting at a dense grid and the nested double integration as in function "vel":

Werner_E_1-1753463557219.png

I could not wait for vel(tt) finishing its calculations 😉

 

OK, i went away when when I came back after quite some time the pot had finished.

It looks like the numeric integral was not converging at some positions where the plot shows gaps.

Werner_E_1-1753466760453.png

Here is one position where the integration fails

Werner_E_2-1753467297872.png

Sometimes it helps to set the system variable TOL to a lower value (default is 10^-3) for a higher precision, but at the cost of an even increasing calculation time

Werner_E_3-1753467372852.png

 

 

 

 

Announcements

Top Tags