The problem works fine within Mathematica and computes the numerical value of the root. However the cdf file shows the equation in the output instead of a numerical root (see image below).
Thank you so much for your direction. Your suggestion seemed to resolve the issue I was having. But now I am getting the following error within the Mathematica nb file:
FindRoot::nlnum: The function value {2. +1. a} is not a list of numbers with dimensions {1} at {x} = {1.}. >>
ReplaceAll::reps: {FindRoot[{func==0}/. {a1->a},{x,1}]} is neither a list of replacement rules nor a
valid dispatch table, and so cannot be used for replacing. >>
Thanks for your help and suggestion again. I completely understand your approach. However my trial case was an attempt to debug a more complex problem, where I needed to have the control for variable ‘a1’ . Modifying my problem definition by moving the function definition within Manipulate like this:
In my attempt to solve the bigger problem, I am still having some issues with Manipulate and FindRoot. I have used your suggestions above.I think I am close but I need some helping hand.
Here is another simplified version of my problem definition:
My objective is to solve a nonlinear equation ‘func’ that has a variable zp that needs to be manipulated by slider. The root of this equation ‘func = 0’ then gets used in the target variable ‘(2. + z0)’ that I need to output within the Manipulate.
I am getting some errors related to the FindRoot as shown below. I would really appreciate some suggestion to modify the code to resolve these errors.
It looks like you want to find the root of 1 + a1*p + a2*p^2 - z == 0 when p has different values from the slider (after multiplying it by 100 ?) The first error you had due to how you over used /. The second issue is FindRoot itself, says
The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a
sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these
tolerances. >>
For the above, you have to change the guess value or look into the suggestions given above.
I really appreciate your continued help. Yes you are correct in stating that I want to find the root of 1 + a1p + a2p^2 - z == 0 when p has different values from the slider (after multiplying it by 100). I tried your suggestedcode but I still get an error:
Moreover, a slider of ‘guess’ for the cdf file will not be an attractive option to the end user.
I decided to modify my function definition to remove the requirement of multiplying slider value of p by 100. I am struggling to understand why my revised and much simplified code for root finding still gives an error:
I tried your suggestedcode but I still get an error:
That is not an error. As I mentioned, it is normal warning of FindRoot :
The line search decreased the step size to within tolerance specified
by AccuracyGoal and PrecisionGoal but was unable to find a
sufficient decrease in the merit function. You may need more than
MachinePrecision digits of working precision to meet these
tolerances.
The above is separate issue from your other error. The fix I did was to to remove your other error. The above warning remains and it is something you have to look into depending on your problem. I added the guess to help you is resolving this warning easier. You can always remove the slider for the guess.
OK, now I understand. I have used your suggestion for Initialization :> to define the function and root finding and that solved my issue.
Thank you again.