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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Function evaluation. Max value based on range variables

Sergey
14-Alexandrite

Function evaluation. Max value based on range variables

Hello!

 

I defined a function depending on one variable. Then I used the range operator for the value which my function depends on. I want to call out the max value of the function based on the range variables. The "max" command doesn't work. I think something is wrong with the equation, since the function can't be evaluated when I type the angle in parenthesis.

Please, take a look ath the attached sheet.

 

Sergey

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:Sergey)

The problem is when you define your function.

You cannot use the convenient convention to write sin^2(x) for sin(x)^2.
If you highlight your function definition and look closely, you  will see an implicit multiplication dot between sin^2 and the opening parenthesis. Obviously that can't work.

The other parenthesis you typed aren't wrong, but not necessary

You have to type it the other way to make it work:

Werner_E_0-1644152905573.png

To find the max value you shouldn't use a range but rather a vector of angles

Werner_E_1-1644153340409.png

Here the max-value is the one at angle zero, for b>a it would be at 90 degree.

Werner_E_2-1644153549063.png

 

 

 

View solution in original post

5 REPLIES 5
Werner_E
24-Ruby V
(To:Sergey)

The problem is when you define your function.

You cannot use the convenient convention to write sin^2(x) for sin(x)^2.
If you highlight your function definition and look closely, you  will see an implicit multiplication dot between sin^2 and the opening parenthesis. Obviously that can't work.

The other parenthesis you typed aren't wrong, but not necessary

You have to type it the other way to make it work:

Werner_E_0-1644152905573.png

To find the max value you shouldn't use a range but rather a vector of angles

Werner_E_1-1644153340409.png

Here the max-value is the one at angle zero, for b>a it would be at 90 degree.

Werner_E_2-1644153549063.png

 

 

 

Sergey
14-Alexandrite
(To:Werner_E)

Thank you, it works.

 

Sergey
14-Alexandrite
(To:Werner_E)

One thing that I do not get is that you are using "phi" with the subscrit of "i". But the functon is dependent on "phi" only. In my case I get an error message (his value must a scalar or a matrix):

Sergey_1-1644154241041.png

 

 

 

Werner_E
24-Ruby V
(To:Sergey)

The difference between ranges and vectors in Mathcad and Prime is always good for confusion.

Ranges should be used just for those three purposes:

1) use a range to index a matrix or vector

2) use a range for the ordinate values in an x-y-plot

3) use a range in a custom program when using a for-loop

 

In case of the i I was using this is just a range to index a vector of 91 angle values. The range starts at 0 because in your case you are using the default value 0 for the system variable ORIGIN.

If you would like to create a vector of angles like 2°, 2.5°,...7°, I would use i:=0..10 and angle[i := (2 + i/2) deg

There is an undocumented feature that if you define a range and immediately  follow the definiton by an evaluation (= sign after the definition) this procedure turns the range into a vector. Thats quite convenient but because its undocumented you take the risk that the feature will not be available anymore in future versions. To define the aforementioned  vector you would simply use angle:=2deg,2.5deg..7deg=
Note that the equal sign at the end is vital and its this equal sign which actually does the conversion trick.

 

The reason you get an error when you type phi_i is possibly because you used the literal index (the one with the shortcut "ctrl and -"). To define a vector element you have to use the matrix index instead. Either from the ribbon menu or use the shortcut "[".

Werner_E_0-1644157157433.png

 

 

I attach the Prime file for your convenience

 

Sergey
14-Alexandrite
(To:Werner_E)

What a great explanation, sir! Thank you. This is very informative.

Top Tags