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

range variable summation

payman
14-Alexandrite

range variable summation

Hello,


In the attached worksheet, inside the function "pulse2", the function L(k, θ, re ,d ,ti ) must be summed over different values of θ. Could you please help me to resolve the error message?

All the best,

Payman

ACCEPTED SOLUTION

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

The commented attached file should help

View solution in original post

17 REPLIES 17
-MFra-
21-Topaz II
(To:payman)

If origin = 0, you can not start qq from -2. Then you should change the loop start, in qq + 2

payman
14-Alexandrite
(To:-MFra-)

Thank you, but I'm not quite sure what you mean.

payman
14-Alexandrite
(To:-MFra-)

Just to make it clear, whatever theta would be later, I want to add the values of "L"  from two cells before to two cells after that.

-MFra-
21-Topaz II
(To:payman)

question03.jpg

-MFra-
21-Topaz II
(To:-MFra-)

I would like to point out that if there is beta in the list of parameters of the function pulse2(...),  instead of beta110, we have:

question031.jpg

LucMeekes
23-Emerald III
(To:payman)

"Just to make it clear, whatever theta would be later, I want to add the values of "L"  from two cells before to two cells after that."

Then you must make sure that Theta is a vector, and it can have indexes running as low as -2. With and ORIGIN setting of 0 that is not possible.

In your program you have a for loop where qq runs from -2 to 2 (in steps of 1).

when it comes to assigning p1 you use qq as the range for a summation. You must realise that what actually occurs is that p1i,1, which is the element of matrix p1 in the i-th row and second column (due to ORIGIN=1) gets assigned a new value five times over (qq runs from -2 to 2).

But it fails at the first attempt, because the summation operator that you used expects qq to be a range. It isn't, it's a value: -2. At the next attempt (well, it doesn't get there, due to the error in the first attempt) it would be again a value: -1 and so forth until qq = +2.

I guess you want to first calculate the sum, then assign it to p1i,1.

The better way to do that is to omit the for-loop assignment and use the summation operator with upper and lower bounds:

Similar for p2.

Now there's another problem, the one that FM was pointing at. Your array theta needs to be an array. You are calling the pulse function with argument beta110, which is an array element at best, not an array, and not with an index below 0 (=ORIGIN).

Success!

Luc

payman
14-Alexandrite
(To:LucMeekes)

Thank you, I see what you mean. I'm going to change the structure of the function.

payman
14-Alexandrite
(To:payman)

Could you please help me with the error message?

The output of the function “pulse2” is the times that the signal received by the left and the right microphones just reaches the threshold value.

But sometimes (as is shown in the worksheet) the signal never reaches the threshold value and hence there is no output . How can I setup the program that in this situation returns (0,0) value so the rest of my program continue working.

Thank you very much

Payman

F.M.‌, LucMeekes

-MFra-
21-Topaz II
(To:payman)

At first glance, since everything depends on the threshold, I made this change where there is a comparison with the threshold. Could it be OK?

question033.jpg

payman
14-Alexandrite
(To:-MFra-)

Then it always returns (0,0) even when the signal reaches the threshold value.

Here is my complete program. The error also affect the next function.

-MFra-
21-Topaz II
(To:payman)

See Werner what he recommends. today I am not in the mood to program.

payman
14-Alexandrite
(To:-MFra-)

Thank you for your suggestions.

Werner_E
25-Diamond I
(To:payman)

Just initialize m1 and m2 as a 1x1 matrix containing a zero.

BTW, it would be better style to initialize j and jj to zero at the top of the program.

Werner_E
25-Diamond I
(To:Werner_E)

Here are two streamlined versions of your pulse2 program. There is no need to create that many (unused) arrays.

The last one running a little bit faster.

If in the case of one of the values being zero you really want to see (0  0) this would be easy to accomplish

payman
14-Alexandrite
(To:Werner_E)

Thank you very much Werner, you are great.

I'm sorry, I am still in trouble with the rest of my program. Would you please take a look.

Werner_E
25-Diamond I
(To:payman)

The commented attached file should help

payman
14-Alexandrite
(To:Werner_E)

Thanks a lot.

Announcements

Top Tags