Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Solving eqn in matlab

Subject: Solving eqn in matlab

From: rasika

Date: 8 Nov, 2011 04:45:16

Message: 1 of 19

C*(50-R)*Ccell - 2.5lnCcell= ln((Is/I)/((1-Is)/I)) - ln B - A*(50-R)
Here A, B and C are constants.. and I have to evaluate Ccell from various values of I, and for a column vector values of R.. but this is the simplest form it can get solved to..
How to get it solved in Matlab?
If I use the solve function it gives me this o/p
syms Cell;
>> solve('C*(50-R)*Cell - 2.5*log(Cell)=log((Is/I)/(1-(Is/I))) - log(B)-A*(50-R)')
 
ans =
 
(50*A - log(-Is*i/(Is*i + 1)) + log(B) - 2.5*log(Cell) + 50*C*Cell)/(A + C*Cell)

Subject: Solving eqn in matlab

From: Roger Stafford

Date: 8 Nov, 2011 06:55:14

Message: 2 of 19

"rasika " <n.rasika@gmail.com> wrote in message <j9ac4r$6b3$1@newscl01ah.mathworks.com>...
> syms Cell;
> >> solve('C*(50-R)*Cell - 2.5*log(Cell)=log((Is/I)/(1-(Is/I))) - log(B)-A*(50-R)')
- - - - - - - - -
  I think you must not have made it clear to 'solve' what your unknown variable is, namely 'Cell'. On my ancient Symbolic Toolbox I got this:

 lambertw(k1/k2*exp(k3/k2))*k2/k1

where I had substituted

 k1 = C*(50-R)
 k2 = -2.5
 k3 = log((Is/I)/((1-Is)/I))-log(B)-A*(50-R)
 x = Cell

to get the equation k1*x+k2*log(x)=k3 and where 'x' was the unknown.

  The function 'lambertw' is given in the Symbolic Toolbox. Note that it possesses two branches. Be careful which one you choose.

  Your own 'solve' should be able to solve this even in the original parameters if you call on it properly.

Roger Stafford

Subject: Solving eqn in matlab

From: rasika

Date: 8 Nov, 2011 07:27:11

Message: 3 of 19

Thanks Roger, I have specified it as syms Cell, that ought to know that it is an unknown variable.. will try the symbolic math toolbox though. that should work.
it doesnt solve it may be because all the Cell terms are not together, I was trying to use taylors series to simplify it further. But if u say math toolbox is able to solve it, then I must check that out.
 I need a numeric value of Cell, when A, B, C constant values are substituted, and for a range of values of R and I,
Thanks again,

"Roger Stafford" wrote in message <j9ajoi$rj3$1@newscl01ah.mathworks.com>...
> "rasika " <n.rasika@gmail.com> wrote in message <j9ac4r$6b3$1@newscl01ah.mathworks.com>...
> > syms Cell;
> > >> solve('C*(50-R)*Cell - 2.5*log(Cell)=log((Is/I)/(1-(Is/I))) - log(B)-A*(50-R)')
> - - - - - - - - -
> I think you must not have made it clear to 'solve' what your unknown variable is, namely 'Cell'. On my ancient Symbolic Toolbox I got this:
>
> lambertw(k1/k2*exp(k3/k2))*k2/k1
>
> where I had substituted
>
> k1 = C*(50-R)
> k2 = -2.5
> k3 = log((Is/I)/((1-Is)/I))-log(B)-A*(50-R)
> x = Cell
>
> to get the equation k1*x+k2*log(x)=k3 and where 'x' was the unknown.
>
> The function 'lambertw' is given in the Symbolic Toolbox. Note that it possesses two branches. Be careful which one you choose.
>
> Your own 'solve' should be able to solve this even in the original parameters if you call on it properly.
>
> Roger Stafford

Subject: Solving eqn in matlab

From: rasika

Date: 8 Nov, 2011 10:20:11

Message: 4 of 19

Can you let me know the exact commands you put in for lambertw fxn, I am having a lill difficulty putting it.

"rasika " <n.rasika@gmail.com> wrote in message <j9alkf$3kk$1@newscl01ah.mathworks.com>...
> Thanks Roger, I have specified it as syms Cell, that ought to know that it is an unknown variable.. will try the symbolic math toolbox though. that should work.
> it doesnt solve it may be because all the Cell terms are not together, I was trying to use taylors series to simplify it further. But if u say math toolbox is able to solve it, then I must check that out.
> I need a numeric value of Cell, when A, B, C constant values are substituted, and for a range of values of R and I,
> Thanks again,
>
> "Roger Stafford" wrote in message <j9ajoi$rj3$1@newscl01ah.mathworks.com>...
> > "rasika " <n.rasika@gmail.com> wrote in message <j9ac4r$6b3$1@newscl01ah.mathworks.com>...
> > > syms Cell;
> > > >> solve('C*(50-R)*Cell - 2.5*log(Cell)=log((Is/I)/(1-(Is/I))) - log(B)-A*(50-R)')
> > - - - - - - - - -
> > I think you must not have made it clear to 'solve' what your unknown variable is, namely 'Cell'. On my ancient Symbolic Toolbox I got this:
> >
> > lambertw(k1/k2*exp(k3/k2))*k2/k1
> >
> > where I had substituted
> >
> > k1 = C*(50-R)
> > k2 = -2.5
> > k3 = log((Is/I)/((1-Is)/I))-log(B)-A*(50-R)
> > x = Cell
> >
> > to get the equation k1*x+k2*log(x)=k3 and where 'x' was the unknown.
> >
> > The function 'lambertw' is given in the Symbolic Toolbox. Note that it possesses two branches. Be careful which one you choose.
> >
> > Your own 'solve' should be able to solve this even in the original parameters if you call on it properly.
> >
> > Roger Stafford

Subject: Solving eqn in matlab

From: Christopher Creutzig

Date: 8 Nov, 2011 13:01:14

Message: 5 of 19

On 08.11.11 05:45, rasika wrote:
> C*(50-R)*Ccell - 2.5lnCcell= ln((Is/I)/((1-Is)/I)) - ln B - A*(50-R)
> Here A, B and C are constants.. and I have to evaluate Ccell from various values of I, and for a column vector values of R.. but this is the simplest form it can get solved to..
> How to get it solved in Matlab?
> If I use the solve function it gives me this o/p
> syms Cell;
>>> solve('C*(50-R)*Cell - 2.5*log(Cell)=log((Is/I)/(1-(Is/I))) - log(B)-A*(50-R)')

When you pass a string to solve, it will completely ignore all values
you have assigned to your MATLAB variables, including Cell, Is, I, etc.
Additionally, I means sqrt(-1) in this context.

Which of the names above represent known values? Do you have values for
A, B, C, R, Is, I, etc., or just assume them to be arbitrary constants?

To make a long story short: Just don't use strings in the solve command.
And it's probably a good habit not to let the system guess which
variable to solve for, either – that works fine if you only have one
variable or you keep in mind the selection rules, but I find it easier
to just be more explicit:

>> syms A B C Cell R Is I
>> solve(C*(50-R)*Cell - 2.5*log(Cell) - ...
       (log((Is/I)/(1-(Is/I))) - log(B)-A*(50-R)), Cell)

ans =

(5*wrightOmega(log(B^(2/5)) + log(1/(-Is/(I*(Is/I - 1)))^(2/5)) -
log(5/(2*C*(R - 50))) - (2*A*(R - 50))/5))/(2*C*(R - 50))


Christopher

Subject: Solving eqn in matlab

From: Steven_Lord

Date: 8 Nov, 2011 14:31:53

Message: 6 of 19



"Christopher Creutzig" <Christopher.Creutzig@mathworks.com> wrote in message
news:4EB9281A.9070102@mathworks.com...
> On 08.11.11 05:45, rasika wrote:
>> C*(50-R)*Ccell - 2.5lnCcell= ln((Is/I)/((1-Is)/I)) - ln B - A*(50-R)
>> Here A, B and C are constants.. and I have to evaluate Ccell from
>> various values of I, and for a column vector values of R.. but this is
>> the simplest form it can get solved to..
>> How to get it solved in Matlab?
>> If I use the solve function it gives me this o/p
>> syms Cell;
>>>> solve('C*(50-R)*Cell - 2.5*log(Cell)=log((Is/I)/(1-(Is/I))) -
>>>> log(B)-A*(50-R)')
>
> When you pass a string to solve, it will completely ignore all values
> you have assigned to your MATLAB variables, including Cell, Is, I, etc.
> Additionally, I means sqrt(-1) in this context.

In addition to what Christopher said, I would avoid using Cell as your
variable name; it's too close to the CELL function and it would be easy to
accidentally type "cell" instead of "Cell" -- if you did, you'd receive an
error.

http://www.mathworks.com/help/techdoc/ref/cell.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Solving eqn in matlab

From: Roger Stafford

Date: 8 Nov, 2011 17:33:14

Message: 7 of 19

"rasika " <n.rasika@gmail.com> wrote in message <j9avor$2r0$1@newscl01ah.mathworks.com>...
> Can you let me know the exact commands you put in for lambertw fxn, I am having a lill difficulty putting it.
- - - - - - - - - -
  I assume you refer to the 'branch' argument in 'lambertw'. I believe it should be set either to 0 or -1 to get the two real branches. Other branch values refer to complex results. Steven Lord can correct me if I am wrong.

Roger Stafford

Subject: Solving eqn in matlab

From: rasika

Date: 9 Nov, 2011 00:38:13

Message: 8 of 19

Hello Christopher,
A,B,C and IS are constants,
A=0.079;
B=6*10^-9;
C=3.5*10^-10;
Is=260;
I will have a column vector of R and I as input.
When i declared all of them under syms i did get the answer like yours
exp((2*log(B))/5 - (2*log(-Is/(I*(Is/I - 1))))/5 - (2*A*(R - 50))/5)/exp(wrightOmega(log(B^(2/5)) + log(1/(-Is/(I*(Is/I - 1)))^(2/5)) + log((2*C*(R - 50))/5) - (2*A*(R - 50))/5))
but it is not a numerical answer. I will change 'I' to 'intensity' or some other variable, because it makes sense why I had got an i in the answer last time now, its taking it as a complex number.
How to pass it then if not as a string?
I tried declaring f=(function to be solved)
and solve(f,Cell) didnt work,.


Christopher Creutzig <Christopher.Creutzig@mathworks.com> wrote in message <4EB9281A.9070102@mathworks.com>...
> On 08.11.11 05:45, rasika wrote:
> > C*(50-R)*Ccell - 2.5lnCcell= ln((Is/I)/((1-Is)/I)) - ln B - A*(50-R)
> > Here A, B and C are constants.. and I have to evaluate Ccell from various values of I, and for a column vector values of R.. but this is the simplest form it can get solved to..
> > How to get it solved in Matlab?
> > If I use the solve function it gives me this o/p
> > syms Cell;
> >>> solve('C*(50-R)*Cell - 2.5*log(Cell)=log((Is/I)/(1-(Is/I))) - log(B)-A*(50-R)')
>
> When you pass a string to solve, it will completely ignore all values
> you have assigned to your MATLAB variables, including Cell, Is, I, etc.
> Additionally, I means sqrt(-1) in this context.
>
> Which of the names above represent known values? Do you have values for
> A, B, C, R, Is, I, etc., or just assume them to be arbitrary constants?
>
> To make a long story short: Just don't use strings in the solve command.
> And it's probably a good habit not to let the system guess which
> variable to solve for, either – that works fine if you only have one
> variable or you keep in mind the selection rules, but I find it easier
> to just be more explicit:
>
> >> syms A B C Cell R Is I
> >> solve(C*(50-R)*Cell - 2.5*log(Cell) - ...
> (log((Is/I)/(1-(Is/I))) - log(B)-A*(50-R)), Cell)
>
> ans =
>
> (5*wrightOmega(log(B^(2/5)) + log(1/(-Is/(I*(Is/I - 1)))^(2/5)) -
> log(5/(2*C*(R - 50))) - (2*A*(R - 50))/5))/(2*C*(R - 50))
>
>
> Christopher

Subject: Solving eqn in matlab

From: rasika

Date: 9 Nov, 2011 00:45:27

Message: 9 of 19

Thanks Steven will remove cell,
 do let me know how to get it solved, it doesnt seem to give any numeric answer.
even if I specify the constants in workspace, it does ignore their values.
I tried Taylor series too assuming that solve might now be working because i have constant*var + log(var) format on LHS., but it doesnt take in the log(cell) term,
I looked up in my help for solve, all examples have strings passed in them, I dont knw how to make matlab take my A,B,C as constants, and I and R as any vectors.
 What I wanted to see was a vector of outputs for Cell.
Thank you,

"Steven_Lord" <slord@mathworks.com> wrote in message <j9begq$jdc$1@newscl01ah.mathworks.com>...
>
>
> "Christopher Creutzig" <Christopher.Creutzig@mathworks.com> wrote in message
> news:4EB9281A.9070102@mathworks.com...
> > On 08.11.11 05:45, rasika wrote:
> >> C*(50-R)*Ccell - 2.5lnCcell= ln((Is/I)/((1-Is)/I)) - ln B - A*(50-R)
> >> Here A, B and C are constants.. and I have to evaluate Ccell from
> >> various values of I, and for a column vector values of R.. but this is
> >> the simplest form it can get solved to..
> >> How to get it solved in Matlab?
> >> If I use the solve function it gives me this o/p
> >> syms Cell;
> >>>> solve('C*(50-R)*Cell - 2.5*log(Cell)=log((Is/I)/(1-(Is/I))) -
> >>>> log(B)-A*(50-R)')
> >
> > When you pass a string to solve, it will completely ignore all values
> > you have assigned to your MATLAB variables, including Cell, Is, I, etc.
> > Additionally, I means sqrt(-1) in this context.
>
> In addition to what Christopher said, I would avoid using Cell as your
> variable name; it's too close to the CELL function and it would be easy to
> accidentally type "cell" instead of "Cell" -- if you did, you'd receive an
> error.
>
> http://www.mathworks.com/help/techdoc/ref/cell.html
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Solving eqn in matlab

From: rasika

Date: 9 Nov, 2011 02:56:14

Message: 10 of 19

okay so here is edited code I am trying and it still wont give me a numeric answer..
I have taken single single values of Intensity and R as of now, to see atleast if it would work for one single value of them both.. then i will put in them as vectors.
syms con
A=0.079;
B=6*10^-9;
C=3.5*10^-10;
R=37;
Is=260;
Intensity=213;
v=3.5*10^-10*(50-37)*con-2.5*2*con^3+19*2.5*con^2+58*2.5*(con-1)-2.5 - log((260/213)/(1-(260/213)))+log(6*10^-9)+0.079*(50-37);
solve(v,con)
it gives out this answer which is obviously not right.
ans =
 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1071410507649966943521088169/(54401661882658312861777920*(((- 4974471010288047340721584908701/81602492823987469292666880000 + (pi*i)/10)^2 -
1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) + 4974471010288047340721584908701/81602492823987469292666880000 - (pi*i)/10)^(1/3)) + (((- 4974471010288047340721584908701/81602492823987469292666880000 + (pi*i)/10)^2 - 1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) + 4974471010288047340721584908701/81602492823987469292666880000 - (pi*i)/10)^(1/3) + 19/6
 19/6 - (((- 4974471010288047340721584908701/81602492823987469292666880000 + (pi*i)/10)^2 - 1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) + 4974471010288047340721584908701/81602492823987469292666880000 - (pi*i)/10)^(1/3)/2 - 1071410507649966943521088169/(108803323765316625723555840*(((- 4974471010288047340721584908701/81602492823987469292666880000 + (pi*i)/10)^2 - 1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) + 4974471010288047340721584908701/81602492823987469292666880000 - (pi*i)/10)^(1/3)) - (3^(1/2)*(1071410507649966943521088169/(54401661882658312861777920*(((- 4974471010288047340721584908701/81602492823987469292666880000 + (pi*i)/10)^2 -
1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) + 4974471010288047340721584908701/81602492823987469292666880000 - (pi*i)/10)^(1/3)) - ((((i*pi)/10 - 4974471010288047340721584908701/81602492823987469292666880000)^2 - 1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) - (i*pi)/10 + 4974471010288047340721584908701/81602492823987469292666880000)^(1/3))*i)/2
 19/6 - (((- 4974471010288047340721584908701/81602492823987469292666880000 + (pi*i)/10)^2 - 1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) + 4974471010288047340721584908701/81602492823987469292666880000 - (pi*i)/10)^(1/3)/2 - 1071410507649966943521088169/(108803323765316625723555840*(((- 4974471010288047340721584908701/81602492823987469292666880000 + (pi*i)/10)^2 - 1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) + 4974471010288047340721584908701/81602492823987469292666880000 - (pi*i)/10)^(1/3)) + (3^(1/2)*(1071410507649966943521088169/(54401661882658312861777920*(((- 4974471010288047340721584908701/81602492823987469292666880000 + (pi*i)/10)^2 -
1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) + 4974471010288047340721584908701/81602492823987469292666880000 - (pi*i)/10)^(1/3)) - ((((i*pi)/10 - 4974471010288047340721584908701/81602492823987469292666880000)^2 - 1229894059828767602863088487172663919800595493110525071958031825589031987595930809/161003938777930272033277984755198449754779470102790777558831365092789977088000)^(1/2) - (i*pi)/10 + 4974471010288047340721584908701/81602492823987469292666880000)^(1/3))*i)/2

"rasika " <n.rasika@gmail.com> wrote in message <j9cif7$lvt$1@newscl01ah.mathworks.com>...
> Thanks Steven will remove cell,
> do let me know how to get it solved, it doesnt seem to give any numeric answer.
> even if I specify the constants in workspace, it does ignore their values.
> I tried Taylor series too assuming that solve might now be working because i have constant*var + log(var) format on LHS., but it doesnt take in the log(cell) term,
> I looked up in my help for solve, all examples have strings passed in them, I dont knw how to make matlab take my A,B,C as constants, and I and R as any vectors.
> What I wanted to see was a vector of outputs for Cell.
> Thank you,
>
> "Steven_Lord" <slord@mathworks.com> wrote in message <j9begq$jdc$1@newscl01ah.mathworks.com>...
> >
> >
> > "Christopher Creutzig" <Christopher.Creutzig@mathworks.com> wrote in message
> > news:4EB9281A.9070102@mathworks.com...
> > > On 08.11.11 05:45, rasika wrote:
> > >> C*(50-R)*Ccell - 2.5lnCcell= ln((Is/I)/((1-Is)/I)) - ln B - A*(50-R)
> > >> Here A, B and C are constants.. and I have to evaluate Ccell from
> > >> various values of I, and for a column vector values of R.. but this is
> > >> the simplest form it can get solved to..
> > >> How to get it solved in Matlab?
> > >> If I use the solve function it gives me this o/p
> > >> syms Cell;
> > >>>> solve('C*(50-R)*Cell - 2.5*log(Cell)=log((Is/I)/(1-(Is/I))) -
> > >>>> log(B)-A*(50-R)')
> > >
> > > When you pass a string to solve, it will completely ignore all values
> > > you have assigned to your MATLAB variables, including Cell, Is, I, etc.
> > > Additionally, I means sqrt(-1) in this context.
> >
> > In addition to what Christopher said, I would avoid using Cell as your
> > variable name; it's too close to the CELL function and it would be easy to
> > accidentally type "cell" instead of "Cell" -- if you did, you'd receive an
> > error.
> >
> > http://www.mathworks.com/help/techdoc/ref/cell.html
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > To contact Technical Support use the Contact Us link on
> > http://www.mathworks.com

Subject: Solving eqn in matlab

From: Nasser M. Abbasi

Date: 9 Nov, 2011 03:18:06

Message: 11 of 19

On 11/8/2011 8:56 PM, rasika wrote:
> okay so here is edited code I am trying and it still wont give me a numeric answer..
> I have taken single single values of Intensity and R as of now, to see atleast
>if it would work for one single value of them both.. then i will put in them as vectors.
> syms con
> A=0.079;
> B=6*10^-9;
> C=3.5*10^-10;
> R=37;
> Is=260;
> Intensity=213;
> v=3.5*10^-10*(50-37)*con-2.5*2*con^3+19*2.5*con^2+58*2.5*(con-1)-2.5 -
>log((260/213)/(1-(260/213)))+log(6*10^-9)+0.079*(50-37);
> solve(v,con)
> it gives out this answer which is obviously not right.
> ans =
>
> snip.. 1071410507649966943521088169/(54401661882658312861777920*(((- 4974471010288047340721584908701/81602492823987469292666880000 + (pi*i)/10)^2 -


I run your code above, and I get (after convert it to double)

EDU>> double(ans)
ans =
  11.7295 - 0.0039i
   0.9082 + 0.0144i
  -3.1377 - 0.0104i

--Nasser

Subject: Solving eqn in matlab

From: rasika

Date: 9 Nov, 2011 07:24:14

Message: 12 of 19

Thanks Nasser, I got some roots
ans =
 
                                                596301325.91576234164749415177267
                                                596301325.91576234164749415177148
                                            0.00079574777275045645780180143342736
          802746443.11830032332298137638464*i - 627820992.62821082772870512092314
        - 802746443.11830032332298137638456*i - 627820992.62821082772870512092287
          802746443.11830032332298137638455*i - 627820992.62821082772870512092287
  0.00024589958501577221974263913391303 - 0.00075680110460163359394390295539747*i
 - 0.0004677288053671182188217140940646*i - 0.00064377347139100044864353985062671
   0.0004677288053671182188217140940646*i - 0.00064377347139100044864353985062671
  0.00075680110460163359394390295539747*i + 0.00024589958501577221974263913391303
        - 802746443.11830032332298137638464*i - 627820992.62821082772870512092314
 
>> double(ans)

ans =

  1.0e+008 *

   5.9630
   5.9630
   0.0000
  -6.2782 + 8.0275i
  -6.2782 - 8.0275i
  -6.2782 + 8.0275i
   0.0000 - 0.0000i
  -0.0000 - 0.0000i
  -0.0000 + 0.0000i
   0.0000 + 0.0000i
  -6.2782 - 8.0275i

>> real(ans)

ans =

  1.0e+008 *

    5.9630
    5.9630
    0.0000
   -6.2782
   -6.2782
   -6.2782
    0.0000
   -0.0000
   -0.0000
    0.0000
   -6.2782

What I need is only one answer for one input of Intensity. That way I can process bulk data of intensity. also I need only real values and most of them above 10^8 range, how should I set a loop for that? my data ranges and can range from 100-1000s of points and I cant have 7-8 roots for every value.and sort manually.
Please suggest me a logic./ loop
"Nasser M. Abbasi" <nma%12000.org@gtempaccount.com> wrote in message <90bc76a0-d5d0-49fc-b8a4-9ec56d4079c5@l24g2000yqm.googlegroups.com>...
> On 11/8/2011 8:56 PM, rasika wrote:
> > okay so here is edited code I am trying and it still wont give me a numeric answer..
> > I have taken single single values of Intensity and R as of now, to see atleast
> >if it would work for one single value of them both.. then i will put in them as vectors.
> > syms con
> > A=0.079;
> > B=6*10^-9;
> > C=3.5*10^-10;
> > R=37;
> > Is=260;
> > Intensity=213;
> > v=3.5*10^-10*(50-37)*con-2.5*2*con^3+19*2.5*con^2+58*2.5*(con-1)-2.5 -
> >log((260/213)/(1-(260/213)))+log(6*10^-9)+0.079*(50-37);
> > solve(v,con)
> > it gives out this answer which is obviously not right.
> > ans =
> >
> > snip.. 1071410507649966943521088169/(54401661882658312861777920*(((- 4974471010288047340721584908701/81602492823987469292666880000 +
(pi*i)/10)^2 -
>
>
> I run your code above, and I get (after convert it to double)
>
> EDU>> double(ans)
> ans =
> 11.7295 - 0.0039i
> 0.9082 + 0.0144i
> -3.1377 - 0.0104i
>
> --Nasser

Subject: Solving eqn in matlab

From: Christopher Creutzig

Date: 9 Nov, 2011 12:45:03

Message: 13 of 19

On 09.11.11 01:38, rasika wrote:
> Hello Christopher,
> A,B,C and IS are constants,
> A=0.079;
> B=6*10^-9;
> C=3.5*10^-10;
> Is=260;
> I will have a column vector of R and I as input.
> When i declared all of them under syms i did get the answer like yours
> exp((2*log(B))/5 - (2*log(-Is/(I*(Is/I - 1))))/5 - (2*A*(R - 50))/5)/exp(wrightOmega(log(B^(2/5)) + log(1/(-Is/(I*(Is/I - 1)))^(2/5)) + log((2*C*(R - 50))/5) - (2*A*(R - 50))/5))
> but it is not a numerical answer. I will change 'I' to 'intensity' or some other variable, because it makes sense why I had got an i in the answer last time now, its taking it as a complex number.
> How to pass it then if not as a string?
> I tried declaring f=(function to be solved)
> and solve(f,Cell) didnt work,.

A variable should either be declared as sym or have a numerical value,
not both, and I don't understand your description of the varable “I”. I
don't know what you tried (please always provide complete input ready
for copy&paste), but this works for me:

A=0.079;
B=6*10^-9;
C=3.5*10^-10;
Is=260;
syms con R I
solve(C*(50-R)*con - 2.5*log(con) - ...
     (log((Is/I)/(1-(Is/I))) - log(B)-A*(50-R)), con)


ans =

(12089258196146291747061760*wrightOmega(log(1/(-260/(I*(260/I -
1)))^(2/5)) - log(12089258196146291747061760/(1692496147460481*R -
84624807373024050)) - (79*R)/2500 -
2635574472465043/439804651110400))/(1692496147460481*R - 84624807373024050)


Since I did not give values for I and R, the answer obviously depends on
them.


Christopher

Subject: Solving eqn in matlab

From: Christopher Creutzig

Date: 9 Nov, 2011 12:51:49

Message: 14 of 19

On 09.11.11 08:24, rasika wrote:
> also I need only real values and most of them above 10^8 range, how should I set a loop for that?

syms con real

will tell the system to only consider real values.

syms con positive

will do the same to restrict to positive values.

evalin(symengine, 'assume(con > 10^8)')

will limit con to real numbers larger than 1e8.


Invoking real() on a solution set will not remove the complex solutions,
but project them onto the real axis, which hardly ever results in a
solution. That's probably not useful.


Christopher

Subject: Solving eqn in matlab

From: rasika

Date: 10 Nov, 2011 01:05:14

Message: 15 of 19

Hello Christopher,
Sorry for not putting in the complete variables,
this the code which is currently working for me
syms con
A=0.079;
B=6*10^-9;
C=3.5*10^-10;
R=37;
Is=260;
Intensity=8.6
v=1+C*(50-37)*con+((C^2*(50-R)^2*con^2)/2)+((C^3*(50-R)^3*con^3)/6)+B*con^-2.5*(1-(Is/Intensity))-(Is/Intensity)*exp(-A*(50-R));

solve(v,con)
but it is giving out all the possible roots like this
ans =
 
                                                596301325.91576234164749415177267
                                                596301325.91576234164749415177148
                                            0.00079574777275045645780180143342736
          802746443.11830032332298137638464*i - 627820992.62821082772870512092314
        - 802746443.11830032332298137638456*i - 627820992.62821082772870512092287
          802746443.11830032332298137638455*i - 627820992.62821082772870512092287
  0.00024589958501577221974263913391303 - 0.00075680110460163359394390295539747*i
 - 0.0004677288053671182188217140940646*i - 0.00064377347139100044864353985062671
   0.0004677288053671182188217140940646*i - 0.00064377347139100044864353985062671
  0.00075680110460163359394390295539747*i + 0.00024589958501577221974263913391303
        - 802746443.11830032332298137638464*i - 627820992.62821082772870512092314
 
>> double(ans)

ans =

  1.0e+008 *

   5.9630
   5.9630
   0.0000
  -6.2782 + 8.0275i
  -6.2782 - 8.0275i
  -6.2782 + 8.0275i
   0.0000 - 0.0000i
  -0.0000 - 0.0000i
  -0.0000 + 0.0000i
   0.0000 + 0.0000i
  -6.2782 - 8.0275i

>> real(ans)

ans =

  1.0e+008 *

    5.9630
    5.9630
    0.0000
   -6.2782
   -6.2782
   -6.2782
    0.0000
   -0.0000
   -0.0000
    0.0000
   -6.2782
 Now what i need is a a single value of con for a single value of Intensity I.
Intensity can be a vector like = [111 8.6 8.5 8.4]'

but for one single value it is giving out so many roots,
 and I have like 100-1000s of values of Intensity, like a bulk data set. Hence I wish to write a code where
1. It will store ans in an array
2.check each element for double and change datatype
2. check for real roots ( and not the real part of the complex roots as it has done for me above)
3. Check for positive roots
4. Check for repeated values
5. Except for the first value check for >10^8 range
 apply all these filters and just get me one value.
 Please help me with that , this would almost be the exact algo i need to follow.
 Thanks

Christopher Creutzig <Christopher.Creutzig@mathworks.com> wrote in message <4EBA7765.6050601@mathworks.com>...
> On 09.11.11 08:24, rasika wrote:
> > also I need only real values and most of them above 10^8 range, how should I set a loop for that?
>
> syms con real
>
> will tell the system to only consider real values.
>
> syms con positive
>
> will do the same to restrict to positive values.
>
> evalin(symengine, 'assume(con > 10^8)')
>
> will limit con to real numbers larger than 1e8.
>
>
> Invoking real() on a solution set will not remove the complex solutions,
> but project them onto the real axis, which hardly ever results in a
> solution. That's probably not useful.
>
>
> Christopher

Subject: Solving eqn in matlab

From: rasika

Date: 10 Nov, 2011 07:45:14

Message: 16 of 19

Can anyone please let me know how to solve the following using lambertw.. it is the same expression, just unsimplified version
exp(K1*X)+b*X^K2(1-K3)=K3*exp(K4)
and K1=3.5*10^-10*(50-R)
K2=-2.5
K3=(Is/Intensity)
K4=-0.079*(50-R)
Can you tell me how to solve this using lambertw?
Is=260
I=[111 8.6 8.4 8.3]';
R=[0:1:37]';
are the values in actual problem,
 But for single values like
for I=111 and R=37 also is fine.. please help



"rasika " <n.rasika@gmail.com> wrote in message <j9f80a$j0q$1@newscl01ah.mathworks.com>...
> Hello Christopher,
> Sorry for not putting in the complete variables,
> this the code which is currently working for me
> syms con
> A=0.079;
> B=6*10^-9;
> C=3.5*10^-10;
> R=37;
> Is=260;
> Intensity=8.6
> v=1+C*(50-37)*con+((C^2*(50-R)^2*con^2)/2)+((C^3*(50-R)^3*con^3)/6)+B*con^-2.5*(1-(Is/Intensity))-(Is/Intensity)*exp(-A*(50-R));
>
> solve(v,con)
> but it is giving out all the possible roots like this
> ans =
>
> 596301325.91576234164749415177267
> 596301325.91576234164749415177148
> 0.00079574777275045645780180143342736
> 802746443.11830032332298137638464*i - 627820992.62821082772870512092314
> - 802746443.11830032332298137638456*i - 627820992.62821082772870512092287
> 802746443.11830032332298137638455*i - 627820992.62821082772870512092287
> 0.00024589958501577221974263913391303 - 0.00075680110460163359394390295539747*i
> - 0.0004677288053671182188217140940646*i - 0.00064377347139100044864353985062671
> 0.0004677288053671182188217140940646*i - 0.00064377347139100044864353985062671
> 0.00075680110460163359394390295539747*i + 0.00024589958501577221974263913391303
> - 802746443.11830032332298137638464*i - 627820992.62821082772870512092314
>
> >> double(ans)
>
> ans =
>
> 1.0e+008 *
>
> 5.9630
> 5.9630
> 0.0000
> -6.2782 + 8.0275i
> -6.2782 - 8.0275i
> -6.2782 + 8.0275i
> 0.0000 - 0.0000i
> -0.0000 - 0.0000i
> -0.0000 + 0.0000i
> 0.0000 + 0.0000i
> -6.2782 - 8.0275i
>
> >> real(ans)
>
> ans =
>
> 1.0e+008 *
>
> 5.9630
> 5.9630
> 0.0000
> -6.2782
> -6.2782
> -6.2782
> 0.0000
> -0.0000
> -0.0000
> 0.0000
> -6.2782
> Now what i need is a a single value of con for a single value of Intensity I.
> Intensity can be a vector like = [111 8.6 8.5 8.4]'
>
> but for one single value it is giving out so many roots,
> and I have like 100-1000s of values of Intensity, like a bulk data set. Hence I wish to write a code where
> 1. It will store ans in an array
> 2.check each element for double and change datatype
> 2. check for real roots ( and not the real part of the complex roots as it has done for me above)
> 3. Check for positive roots
> 4. Check for repeated values
> 5. Except for the first value check for >10^8 range
> apply all these filters and just get me one value.
> Please help me with that , this would almost be the exact algo i need to follow.
> Thanks
>
> Christopher Creutzig <Christopher.Creutzig@mathworks.com> wrote in message <4EBA7765.6050601@mathworks.com>...
> > On 09.11.11 08:24, rasika wrote:
> > > also I need only real values and most of them above 10^8 range, how should I set a loop for that?
> >
> > syms con real
> >
> > will tell the system to only consider real values.
> >
> > syms con positive
> >
> > will do the same to restrict to positive values.
> >
> > evalin(symengine, 'assume(con > 10^8)')
> >
> > will limit con to real numbers larger than 1e8.
> >
> >
> > Invoking real() on a solution set will not remove the complex solutions,
> > but project them onto the real axis, which hardly ever results in a
> > solution. That's probably not useful.
> >
> >
> > Christopher

Subject: Solving eqn in matlab

From: Christopher Creutzig

Date: 10 Nov, 2011 07:59:00

Message: 17 of 19

On 10.11.11 02:05, rasika wrote:

> and I have like 100-1000s of values of Intensity, like a bulk data set. Hence I wish to write a code where
> 1. It will store ans in an array

sol = solve(v,con);

> 2.check each element for double and change datatype

sol = double(sol);

> 2. check for real roots ( and not the real part of the complex roots as it has done for me above)

sol = real(sol(abs(imag(sol)) < eps(real(sol))));

or, if you wish to ignore the possibility of spurious imaginary parts,

sol = sol(imag(sol) == 0);

> 3. Check for positive roots

sol = sol(sol > 0);

> 4. Check for repeated values

Within which precision? I.e., when do you regard two floating point
numbers to be identical?

sol = unique(sol);

> 5. Except for the first value check for >10^8 range

I'm not sure what you mean by “except for the first value.” Do you mean
except for the first intensity? Else, what is “the first value,” given
that the results of solve are in arbitrary order that can change at any
time?

sol = sol(sol > 1e8);

> apply all these filters and just get me one value.

It's probably easier to deviate from the steps you wrote above and do
this instead:

sol = double(solve(v,con));
res = max(real(sol(abs(imag(sol)) < eps(real(sol)))));

Move sub-expressions to temporary variables as needed to make the code
readable for you. Personally, I tend not to use many of those.


Christopher

Subject: Solving eqn in matlab

From: rasika

Date: 10 Nov, 2011 08:17:33

Message: 18 of 19

Okay, I think that should work. I was also trying to solve the same thing using lambertw, since this solve answer has errors of order 10^3 from what is expected.
Can you please help me with that
I will post that doubt again

Can anyone please let me know how to solve the following using lambertw.. it is the same expression, just unsimplified version
exp(k1*X)+k5*(X^k2)*(1-k3)=k3*exp(k4)
k1=3.5*10^-10*(50-R);
k2=-2.5;
k3=(Is/Intensity);
k4=-0.079*(50-R);
k5=6*10^-9;



Can you tell me how to solve this using lambertw?
Is=260
I=[111 8.6 8.4 8.3]';
R=[0:1:37]';
are similar to the values in actual problem,
 But for single values like
for I=111 and R=37 also is fine.. please help


Christopher Creutzig <Christopher.Creutzig@mathworks.com> wrote in message <4EBB8444.7090803@mathworks.com>...
> On 10.11.11 02:05, rasika wrote:
>
> > and I have like 100-1000s of values of Intensity, like a bulk data set. Hence I wish to write a code where
> > 1. It will store ans in an array
>
> sol = solve(v,con);
>
> > 2.check each element for double and change datatype
>
> sol = double(sol);
>
> > 2. check for real roots ( and not the real part of the complex roots as it has done for me above)
>
> sol = real(sol(abs(imag(sol)) < eps(real(sol))));
>
> or, if you wish to ignore the possibility of spurious imaginary parts,
>
> sol = sol(imag(sol) == 0);
>
> > 3. Check for positive roots
>
> sol = sol(sol > 0);
>
> > 4. Check for repeated values
>
> Within which precision? I.e., when do you regard two floating point
> numbers to be identical?
>
> sol = unique(sol);
>
> > 5. Except for the first value check for >10^8 range
>
> I'm not sure what you mean by “except for the first value.” Do you mean
> except for the first intensity? Else, what is “the first value,” given
> that the results of solve are in arbitrary order that can change at any
> time?
>
> sol = sol(sol > 1e8);
>
> > apply all these filters and just get me one value.
>
> It's probably easier to deviate from the steps you wrote above and do
> this instead:
>
> sol = double(solve(v,con));
> res = max(real(sol(abs(imag(sol)) < eps(real(sol)))));
>
> Move sub-expressions to temporary variables as needed to make the code
> readable for you. Personally, I tend not to use many of those.
>
>
> Christopher

Subject: Solving eqn in matlab

From: Christopher Creutzig

Date: 10 Nov, 2011 08:26:29

Message: 19 of 19

On 10.11.11 09:17, rasika wrote:
> Can anyone please let me know how to solve the following using lambertw.. it is the same expression, just unsimplified version
> exp(k1*X)+k5*(X^k2)*(1-k3)=k3*exp(k4)

That is not the same expression at all, and I doubt the solution can be
expressed in terms of lambertW.


Christopher

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us