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

The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.

newbie question, functions

KarstenJ
4-Participant

newbie question, functions

Prime 7

KarstenJ_0-1640095803272.png

I am trying to calculate volume of a cone as a function, in steps of 0.3 meters.
I'm not sure what I'm doing wrong.
can someone enlighten me?

 

thanks in advance

ACCEPTED SOLUTION

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

From what I had seen in the sheet I assumed that only cones with a ratio of r : h = 2.5 : 6 should be considered with h running up to 6m.

If you should be able to choose r and h independently of each other, then I would rather define a function in both variables.

The picture shows how to get the values seen in Stuarts screen shot. r is the vector you already defined and while vectorizing is not mandatory here, I still think it's a good habit to do so.

Werner_E_0-1640102492755.png

 

 

View solution in original post

4 REPLIES 4
Werner_E
25-Diamond I
(To:KarstenJ)

You were running into Primes infamous autolabelling feature.

Look closely at t"he "h" on the RHS of the definiton of f(h). You'll notice its coloured green like the symbol pi. That means its labelled as being a constant.

There is a predefined constant h built into Prime:

Werner_E_0-1640097056049.png

and thats the reason for the strange result you see.

Manually label that h as being a variable

AND

delete the "f(h):=" because you obviously don't want to define a function

AND

vectorize the expression

and you should see what you expect.

Werner_E_1-1640097488558.png

 

Werner_E
25-Diamond I
(To:Werner_E)

If you want to define a function and also want to explicitly use a variable r in your formula, you could do it that way:

Werner_E_2-1640097682153.png

Again you have to vectorize the function call!

 

Note that you defined h as a range but you turned it into a vector (by using the undocumented trick to immediately evaluate after the definition).

Thats the reason you have to use vectorization also when you plot the function (left plot; plotting one vector over the other)

If you define a range (like hh in the plot to the right), you don't need to vectorize

Werner_E_3-1640098024879.png

 

StuartBruff
23-Emerald III
(To:KarstenJ)


@KarstenJ wrote:

Prime 7

KarstenJ_0-1640095803272.png

I am trying to calculate volume of a cone as a function, in steps of 0.3 meters.
I'm not sure what I'm doing wrong.
can someone enlighten me?


 

And here's an additional, slightly different version to Werner's.

 

2021 12 21 d.png

 

2021 12 21 e.png

 

Stuart

Werner_E
25-Diamond I
(To:StuartBruff)

From what I had seen in the sheet I assumed that only cones with a ratio of r : h = 2.5 : 6 should be considered with h running up to 6m.

If you should be able to choose r and h independently of each other, then I would rather define a function in both variables.

The picture shows how to get the values seen in Stuarts screen shot. r is the vector you already defined and while vectorizing is not mandatory here, I still think it's a good habit to do so.

Werner_E_0-1640102492755.png

 

 

Announcements

Top Tags