Post Reply 
Evaluate function with parameter
02-14-2022, 07:44 PM
Post: #1
Evaluate function with parameter
Say I want to evaluate a function including a parameter, e.g.
F1(X) = 12*p*X^2 - 50*X^3

Parameter p is within an interval [16, 24] with step=1.

- Would it be possible to plot these 9 graphs alongside eachother?
- Would it be possible to generate a table with columns for different values of p?
Find all posts by this user
Quote this message in a reply
02-14-2022, 08:20 PM
Post: #2
RE: Evaluate function with parameter
Inside the "Function" app, run the following code:

Code:
EXPORT main
BEGIN
FOR I FROM 1 TO 9 DO
EXPR("F"+I+":='12*"+(I+15)+"X^2-50*X^3'");
CHECK(I);
END;
END;

For the graph, use plot view, and for the table, use numeric view.
Find all posts by this user
Quote this message in a reply
02-14-2022, 09:29 PM
Post: #3
RE: Evaluate function with parameter
The Prime doesn’t support natively parameterized functions, but you can easily create a custom app for that:

Save the Function app under a new name, for example F-Param
Select F-Param as the current app
In Program open F-Param (on the top of the program list)
Replace :
Code:
//START()
//BEGIN
// MSGBOX("START");
//END;
by:
Code:
START()
BEGIN
 LOCAL F,p,I,J,S;
 INPUT({{F,[2],{30,70,1}},{p,[2],{30,70,2}},{I,[4],{30,70,3}},{S,[0],{30,70,4}}},"FUNCTION AND PARAMETER",{"Function","Parameter","Interval","Step"});
 FOR J FROM 0 TO 9 DO
  EXPR("F"+J+":=\"\"");
 END;

 K:=1;
 FOR J FROM I(1) TO I(2) STEP S DO
  EXPR("F"+K+":="+STRING(REPLACE(F,p,STRING(J))));
  CHECK(K);
  K:=K+1;
 END;
END;
Press Check and Esc

Now when you launch F-Param you need to enter your parameterized function (12*p*X^2 - 50*X^3), the parameter (p), the interval ([16,24]) and the step (1).
This will fill the different functions so you can plot them and view the table in the numeric view.
Find all posts by this user
Quote this message in a reply
02-15-2022, 06:09 PM
Post: #4
RE: Evaluate function with parameter
That's very nice of you, Didier, creating a specialized function for me.
Something new to me.

I'm trying this on the Virtual Calculator and I must admit that I kind'a get lost along the way.
- I managed to save the Function app under another name, thus creating a new app
- I select this new app
- I press [shift][1] for program
- There it displays "Function (App)"
- If I then select the option Edit, I get an empty code editor screen without the code you mention to be replaced

I've also tried to use the Connectivity kit to copy your code into the Virtual Calculator, but there too I was not able to work out how to do this.
Find all posts by this user
Quote this message in a reply
02-15-2022, 08:10 PM
Post: #5
RE: Evaluate function with parameter
(02-15-2022 06:09 PM)StephanP Wrote:  I've also tried to use the Connectivity kit to copy your code into the Virtual Calculator, but there too I was not able to work out how to do this.

I've tried this code also without success on the virtual Prime. After I created the F-Param, pushed <SHIFT> <1> to open the Program catalog. Then opened the "F-Param"

First observation: there is no block like this
Code:
//START()
//BEGIN
// MSGBOX("START");
//END;

The screen is empty. So nothing to delete. Copied the proposed code completely into the virtual Prime. <Check> Reports "Error: Syntax Error". Leaving the editor with <Esc> is accompanied by the message "Syntax error in program line 1". That line is 'START()'
@Didier: perhaps we need to check the Sw-Version.

Here it is "Build: 2.1.14592(2012 6 9)

Günter
Find all posts by this user
Quote this message in a reply
02-15-2022, 09:48 PM (This post was last modified: 02-16-2022 05:16 PM by Didier Lachieze.)
Post: #6
RE: Evaluate function with parameter
Yes, it seems that with the latest software versions the content of the program part of the standard apps has changed. When you open the Function (App) in the program catalog the name is Function:main(Cas), so it seems to expect a CAS program, not a PPL one.

I initially did it with the iOS Prime app which has still the old apps content.

So I've copied the content of my custom app to the connectivity kit and then to the virtual Prime on Windows and it worked fine, I've then transferred the custom app to my Prime G2 with the latest firmware and it worked fine also.

So here it is. You need to extract the .hpappdir file from the zip file and then drag and drop to the connectivity kit to your virtual or physical Prime.

EDIT: I've refined the app to include checks on the number of parameter values to ensure they are within the number of functions available in the Symb view (10) and F0 will now be used for the 10th value of the parameter. I've also made the Input values persistent by moving the related variables from Local to App variables, so that when reopening F-Param you will keep the previous input values. This can be useful when you want to just change some of them, such as the interval or the number of steps.


.zip  F-Param.hpappdir.zip (Size: 1.69 KB / Downloads: 19)


When launching F-Param you should get an input screen such as this one:
   

Then you'll get to the Symb view with all appropriate functions populated and checked:
   

The Input variables are now in the F-Param App Program variables:
   
Find all posts by this user
Quote this message in a reply
02-15-2022, 11:00 PM
Post: #7
RE: Evaluate function with parameter
Thanks Didier, that looks great.

wonder what all these out commented lines are for.
Find all posts by this user
Quote this message in a reply
02-16-2022, 06:43 AM (This post was last modified: 02-16-2022 06:44 AM by Didier Lachieze.)
Post: #8
RE: Evaluate function with parameter
(02-15-2022 11:00 PM)Guenter Schink Wrote:  wonder what all these out commented lines are for.

I think they are a template for the different functions you can use in a custom app.
Find all posts by this user
Quote this message in a reply
02-16-2022, 05:14 PM (This post was last modified: 02-16-2022 05:14 PM by Didier Lachieze.)
Post: #9
RE: Evaluate function with parameter
I've updated my post above with a more refined version of the custom app.
Find all posts by this user
Quote this message in a reply
02-19-2022, 09:12 PM
Post: #10
RE: Evaluate function with parameter
Thanks, Didier
Much obliged
Find all posts by this user
Quote this message in a reply
09-24-2023, 01:50 AM
Post: #11
RE: Evaluate function with parameter
(02-15-2022 09:48 PM)Didier Lachieze Wrote:  Yes, it seems that with the latest software versions the content of the program part of the standard apps has changed. When you open the Function (App) in the program catalog the name is Function:main(Cas), so it seems to expect a CAS program, not a PPL one.

Thanks for explicitly bringing this up. As I mentioned in a referring post, I filed a bug report for this on the bug tracking site I’ve set up and it's since been addressed. Big Grin (The current internal build again has the default as PPL.)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: