ParseToFunction for function using variables other than x

lewws shared this question 7 months ago
Answered

Hi,

Need some guidance on this.


Check button has the following script.

ParseToFunction[f,textInputf]

ParseToFunction[g,textInputg]


Possible to parse to a function where the variable is not x?

Already predefined f as a function of r by f(r) = r , but parsing “2r” to f does not work.


Any workaround to check answers like this?

Comments (8)

photo
1

If you define eg

f(t)=sin(t)

then you can link the Input Box directly to that

photo
1

In other words, avoid parsing through a textInput variable

I used the text variable textInput so that when starting each question, the input box can be empty. Linking directly forces the default value sin(t) to appear....

Any scheme to make the inputbox blank?

photo
1

Try f(t)=?


(that's the nearest to blank)

photo
1

Sorry. I tried. Can't work.

Problem is f(r) = r (initially) will accept from input box directly when we type in 2r.

But once reset to f(r) = ? f no longer knows r as a variable of the function..

Any way around this?


Some time back the idea of having a better inputbox was to have the inputbox connected to a text variable which can be initialized as "" (blank). And then upon using a button script, ParseToNumber or ParseToFunction can transfer from the text variable to the numerical or function variable.

Can we have a workaround for this problem above if we are not going to tweak Geogebra?

photo
1

Hi lewws,

A solution with Execute() tested in GGB 5.0 & 6.0

It's works (exception: correct GGB message with wrong text when x is using in the expression),

but I don't know why it's works, because the script in frText redefine f(r).

Normally this give problems in dependencies but not in this context.

Maybe a usefull GGB bug :wink:

photo
1

Thanks rami.

Your solution works too.

I experimented and came up with this :

Workaround :

InputBox1 is linked to variable textInputf initially so that it can show blank (“”) in the inputbox

After typing in the correct answer, and clicked on Check button,

the following key commands are called to update function f and change InputBox1 attributes

: Execute[{“f(r) =”+textInputf}]

InputBox1 =InputBox(f)


(f(r) is kept defined with f(r) = 99. g(x) need not worry as it will accept ParseToFunction in variable x.


AND.... IT'S WORKING!


Thanks Michael and rami!

photo
photo
1

If the name of the function-variable must be variable

(for example: if enter by user or modified by question-app)

photo
1

Yes, thanks

photo
© 2019 International GeoGebra Institute