Asked by Mac Sampson
on 21 Sep 2012

I am trying to solve an equation involving a common logorithm within a loop. I first solve an equation to get r(i). then I take that r(i) value and plug it into an equation to solve for b(i).The second equation is:

b(i)=solve('r(i)=.5*Log10(b(i)) + .5*b(i)')

It is having a lot of trouble solving this. This is the error message:

Warning: Could not find an exact (case-sensitive) match for 'Log10'. /Applications/MATLAB_R2009aSV.app/toolbox/matlab/elfun/log10.m is a case-insensitive match and will be used instead. You can improve the performance of your code by using exact name matches and we therefore recommend that you update your usage accordingly. Alternatively, you can disable this warning using warning('off','MATLAB:dispatcher:InexactCaseMatch'). This warning will become an error in future releases. > In testloopwithgraph at 6 ??? Error using ==> mupadengine.mupadengine>mupadengine.feval at 162 Error: no indeterminate(s) [numeric::solve]

Error in ==> solve>mupadSolve at 232 list = feval(symengine,'mlfsolve',eqns,vars);

Error in ==> solve at 93 [R,symvars,order] = mupadSolve(eqns,vars);

Error in ==> testloopwithgraph at 7 b(i)=solve('r(i)=.5*Log10(b(i)) + .5*b(i)');

I can numericaly solve this equation in mathematica with just a warning about how the output might not cover all values, but it does give me values. In my matlab code it won't give me values at all. Is there a way around this?

*No products are associated with this question.*

Answer by Azzi Abdelmalek
on 21 Sep 2012

Edited by Azzi Abdelmalek
on 21 Sep 2012

use

log10

not

Log10

Show 3 older comments

Mac Sampson
on 21 Sep 2012

could you explain this a bit more?

syms B [...] r(i) = [...] b(i) = solve(r(i) = 1/2*log10(B)+1/2*B, B);

Azzi Abdelmalek
on 21 Sep 2012

do you want to use symbolic toolbox. In your case, implicit solution could'nt be found, unless you use just

syms b

%with r known

syms b

sol=solve(-r(1)+0.5*log10(b)+0.5*b,b)

Mac Sampson
on 21 Sep 2012

so this code would go within the loop and without noting r and b as r(i) and b(i)?

Answer by Matt Tearle
on 21 Sep 2012

If I understand your intent correctly, you're trying to solve the equation

r_i = (Log10(b) + b)/2

for b, given a (numeric?) value of r_i. Then you want to store that b value as b_i. (Repeat for i+1)

If so, then (1) you don't need to do this symbolically and (2) you are getting the error because `solve` can't figure out what the variable is.

I'd suggest using `fzero`:

for i = 2:n % get r(i) % solve for b(i) using b(i-1) as an initial guess b(i) = fzero(@(b) (log10(b) + b)/2 - r(i),b(i-1)); end

Show 1 older comment

Matt Tearle
on 21 Sep 2012

`fzero` is failing to find the root.

Mac Sampson
on 21 Sep 2012

Matt Tearle
on 21 Sep 2012

Yes, I understand that, but `fzero` is a numerical solver, so it requires an initial guess for the solution. When doing stuff like this in a loop, it's not uncommon to use the previous solution as the starting point for the next solution. If r(i) varies somewhat slowly and smoothly with i, that would make sense. But it looks like maybe that's not the case here.

So, see my new answer...

Answer by Matt Tearle
on 21 Sep 2012

Edited by Matt Tearle
on 21 Sep 2012

Didn't see your comment with your code. This works:

imax = (n/2)-2; r = zeros(imax,1); syms b

for i = 2:imax; r(i)=.5*log10((2*p)^((1 - 2*(i - 2))/(n - 4))*(t/2)^((2*(i - 2))/(n - 4)))+(i - 2)*(((n - 4)*p-2*p-.5*t)/(n - 4)); bsolve(i)=solve((log10(b) + b)/2 == r(i),b); end

bnum = double(bsolve);

Show 5 older comments

Walter Roberson
on 22 Sep 2012

Mac Sampson
on 22 Sep 2012

Walter Roberson
on 22 Sep 2012

b(i) in terms of r(i) is the formula I show above, involving LambertW .

I tested in Maple and the results appear to be correct. However, in cases where r(i) is complex, there can be multiple solutions.

Answer by Mac Sampson
on 22 Sep 2012

Thanks so much to all of you. I believe with your help I have found what is wrong and will embark on tracking down and fixing the problem. Thanks again for all your help!

Opportunities for recent engineering grads.

## 4 Comments

## Azzi Abdelmalek (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/48772#comment_100726

what is b(i)?

## Mac Sampson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/48772#comment_100728

b(i) is the new variable i want to solve for. here is the complete loop:

## Azzi Abdelmalek (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/48772#comment_100729

## Mac Sampson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/48772#comment_100736

thanks for catching that. that was a typo