MATLAB Answers

## Doubt math

Asked by Nuno

### Nuno (view profile)

on 6 Apr 2011
Latest activity Commented on by Image Analyst

### Image Analyst (view profile)

on 15 Oct 2015
Accepted Answer by Matt Tearle

### Matt Tearle (view profile)

I have the next expression and my unknown is "I".

```I = ICC - IR.*(2.718.^((V1+Rs*I)./(m.*VT))-1) - ((V1+Rs.*I)/Rp);
```

Exist any function im Matlab that resolve this expression without math methods?

## Products

No products are associated with this question.

## 4 Answers

### Matt Tearle (view profile)

Answer by Matt Tearle

### Matt Tearle (view profile)

on 7 Apr 2011
Accepted answer

OK, to expand on the cyclist's answer:

1. rewrite your equation in the form f(I) = 0: ICC - IR.*(exp((V1+Rs*I)./(m.*VT))-1) - ((V1+Rs.*I)/Rp) - I = 0
2. having defined all the constants (ICC, m, VT, etc), make a function of I using an anonymous function handle: f = @(I) ICC - IR.*(exp((V1+Rs*I)./(m.*VT))-1) - ((V1+Rs.*I)/Rp) - I;
3. apply fsolve to f

Like Walter, I'm assuming 2.718.^foo really means e^foo, which, in MATLAB, should be implemented as exp(foo).

Walter Roberson

### Walter Roberson (view profile)

on 11 Apr 2011

No, you can only solve for a single value of V1 if you are using fzero() . You could solve over multiple V1 if you had the optimization toolkit and fsolve() but the setup would change.

If you go back to the symbolic LambertW expression that I showed, then you should be able to vectorize that.

Nuno

### Nuno (view profile)

on 11 Apr 2011

This expression:

-(V1-(-LambertW(-Rs*IR*Rp*exp(Rp*(Rs*ICC+Rs*IR+V1)/(m*VT*(Rp+Rs)))/(-Rs*m*VT-Rp*m*VT))+Rp*(Rs*ICC+Rs*IR+V1)/(m*VT*(Rp+Rs)))*m*VT)/Rs

But, how do you transform the expression in this form?

Walter Roberson

### Walter Roberson (view profile)

on 11 Apr 2011

I used a different symbolic package to get that, but it is likely that solve() like Tim showed should be able to handle it.

### Matt Fig (view profile)

Answer by Matt Fig

### Matt Fig (view profile)

on 6 Apr 2011

What do you mean "without math methods?" MATLAB uses only math methods as far as I know...

Matt Tearle

### Matt Tearle (view profile)

on 7 Apr 2011

Yeah, we wouldn't want any awkwardly named functions...

**cough CUMTRAPZ cough***

Image Analyst

on 12 Oct 2012

Or "ASSEMPDE".

Image Analyst

### Image Analyst (view profile)

on 15 Oct 2015

A new funny one is "removecats" (in the Statistics and Machine Learning Toolbox). People have been trying to use it on youtube and Facebook videos.

### the cyclist (view profile)

Answer by the cyclist

### the cyclist (view profile)

on 6 Apr 2011

You could use the function "fzero" to solve this equation.

Nuno

### Nuno (view profile)

on 7 Apr 2011

But how fzero resolve this problem?

### Tim Zaman (view profile)

Answer by Tim Zaman

### Tim Zaman (view profile)

on 6 Apr 2011

I guess what you need is just a solver; for example you define

syms ICC IR V1 Rs m VT Rp;

solve('I = ICC - IR.*(2.718.^((V1+Rs*I)./(m.*VT))-1) - ((V1+Rs.*I)/Rp)')

-untested-

Walter Roberson

### Walter Roberson (view profile)

on 6 Apr 2011

Symbolically, assuming 2.718 represents exp(1),

-(V1-(-LambertW(-Rs*IR*Rp*exp(Rp*(Rs*ICC+Rs*IR+V1)/(m*VT*(Rp+Rs)))/(-Rs*m*VT-Rp*m*VT))+Rp*(Rs*ICC+Rs*IR+V1)/(m*VT*(Rp+Rs)))*m*VT)/Rs

Ugly. But it is the standard form to solve such equations, which is a fact you would have to know through mathematical experience as the Lambert W function is not one of the obvious ones.

Nuno

### Nuno (view profile)

on 7 Apr 2011

Ups... I don't understand...

Walter Roberson

### Walter Roberson (view profile)

on 7 Apr 2011

"How this works" is that the symbolic solver does pattern matching and determines that the expression matches a pattern that it knows how to solve. It then substitutes the components from your actual expression in to the general solution to the kind of problem that it has decided your expression is. It so happens that the pattern matched is one whose answer is expressed in terms of the Lambert W function. _Why_ the Lambert W function is the answer for those kinds of problems is a topic for a series of lectures in complex analysis.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

New to MATLAB?