Skip to main content
1-Visitor
March 2, 2020
Question

LambertW-function can't solve for unitless variables and vector with more than 9 values

  • March 2, 2020
  • 4 replies
  • 4577 views

Dear community, 

 

I am trying to calculate the current I dependent of V of a photovoltaik cell in . To solve this equation I am using the LambertW function. Unfortunately, I ran into two problems that I have not figured out yet:

 

1. I wanted to define the argument LambertW-function W(z) in symbolic form, i.e. I wanted to type out equation I want to use for z inside the parentheses of the LamberW-function. I made sure that all the units in the function cancel each other out. Nonetheless I receive an error, that "This value has unit voltage, but needs to have unit unitless". If I just solve the argument z of the function the value is unitless. The expression W(z) can be solved though however if I provide unitless variables. I achieved this by dividing each variable by its respective unit, therefore making the input unitless. This bothers me a little though since I haven't found the reason for this problem or how to solve it.

 

2. I wanted to plot the function W in depence of V. To do this I defined a vector U[k with kmax steps for my voltage. The solver can't finde a solution if kmax is greater than 8. Even in my simple example I only get "NaN" as a result if kmax is 9.  I didn't change the maximim and minimum voltages, just the step width. However if I calculate the values of the argument z of the LambertW-function before I calculate W(z) I can use a kmax greater than 8.

 

Does anybody have an idea why my original solution doesn't work and why I can't calculate more than 9 values when using kmax=8 ? Thank you very much in advance!

4 replies

25-Diamond I
March 2, 2020

The symbolic does not know anything about units.

How about this approach?

Werner_E_0-1583172672983.png

 

25-Diamond I
March 2, 2020

A better approach:

Werner_E_0-1583172908784.png

 

25-Diamond I
March 2, 2020

According your second problem:

You must be aware, that the mix of symbolic and numeric evaluation can cause more problems you may think.

Your function f.sym looks like it returns a true numeric result, buts thats not true. Its still kind of a symbolic value.

The reason for your calculation failing when trying to calculate a vector with more than 9 elements is because mathcads numeric switches by default from "matrix" display to a scrollable "table" display if the vector has more than 9 elements.

You can get the result if you change the output from "table" to "matrix" via the "Result Format" menu (double click on the result):

Werner_E_0-1583173759374.png

 

Furthermore its NOT a vector because of the way you use the range  variable k. You get a vector if you assign something like F[k:=f.sym(....) :

Werner_E_1-1583173804059.png

But chances are that this vector will not always behave like a true numeric valued vector.

 

To avoid the problem with the mix of symbolic and numeric you may want to search the forum for some threads where true numeric functions were posted for the calculation of the lambertW function.

The search function in this forum is not really helpful and when switching from one forum software to another PTC succeeded even twice in ruining the older forum threads and links. So the only link I can provide after a quick search is

https://community.ptc.com/t5/PTC-Mathcad/Lambert-W-Symbolic-Evaluation/m-p/405220/highlight/true#M158870

but I know that there were also other implementations. On the other hand is a sheet from Stuart sure not a bad choice 😉

 

23-Emerald IV
March 2, 2020

Attached is a Mathcad 11 file with an implementation of the LambertW 'function' that corresponds well with the symbolic equivalent:

LucMeekes_0-1583182551595.png

Success!
Luc

12-Amethyst
March 3, 2020

Dear Luc,

your MC 11 does not work in MC 15 (not PRIME) anymore. Why?

Thanks

Walter

 

23-Emerald IV
March 3, 2020

That may be because it uses, essentially symbolically evaluates, the symbolic Lambert 'function': W(). This function may not exist in MuPad...

On that one line where it is used, replace

W(1) float, 12 ->

by the numeric value, which is: 0.567143290409784

 

LucMeekes_0-1583240694887.png

Try if it runs after you change that.

 

Success!
Luc

21-Topaz II
March 4, 2020

Hi,

answer4.jpg