I would like to solve the equation:
1/2*logninv(x, 0.03-1/2*0.2^2 + log(100), 0.2^2) +1/2*logninv(x, 0.03-1/2*0.1^2 + log(100), 0.1^2) == 100
I can solve this using excel with the solver, but I'm trying to solve it with matlab, I use the code:
vpasolve(1/2*logninv(x, 0.03-1/2*0.2^2 + log(100), 0.2^2) +1/2*logninv(x, 0.03-1/2*0.1^2 + log(100), 0.1^2) == 100,x,0.24)
but this gives me following error:
Error using symfun>validateArgNames (line 175)
Second input must be a scalar or vector of unique symbolic variables.
Error in symfun (line 42)
y.vars = validateArgNames(inputs);
Error in sym/subsasgn (line 1452)
C = symfun(B,[inds{:}]);
Error in logninv (line 60)
p(p < 0 | 1 < p) = NaN;
from which I deduce that I need to tell matlab that x must be between 0 and 1 so then I use:
vpasolve(1/2*logninv(x, 0.03-1/2*0.2^2 + log(100), 0.2^2) +1/2*logninv(x, 0.03-1/2*0.1^2 + log(100), 0.1^2) == 100,x<1,x>0,[x])
but this gives me the error:
Error using symfun>validateArgNames (line 175)
Second input must be a scalar or vector of unique symbolic variables.
Error in symfun (line 42)
y.vars = validateArgNames(inputs);
Error in sym/subsasgn (line 1452)
C = symfun(B,[inds{:}]);
Error in logninv (line 60)
p(p < 0 | 1 < p) = NaN;
You want to find the position within an interval at which a function attains a specific value. This can be framed as an optimization problem: Where is the deviation of the function value from the specific value minimal? Since the variable is bounded to an interval, we can use
fminbndfrom the Optimization Toolbox.Define the function:
Define a function that computes the deviation or error:
Solve the optimization problem:
The result is 0.23993814958158.
Let's check whether the error could be brought down to zero:
The result is 0.000121288471035541. Considering that the function value goes from 0 at 0 to 110 at 0.99, that is an acceptable precision.
If necessary, the precision can be increased by setting
TolXand possibly other options viaoptimset:Now the result is 0.239922902427111, and the remaining error is 1.49937875448813 · 10-8.
Note that
TolXspecifies the precision to which $x$ is estimated, not the acceptable size of the remaining error. The default value is1e-4.