cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

4-Participant

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

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!

13 REPLIES 13
24-Ruby V
(To:mlavery)

The symbolic does not know anything about units.

24-Ruby V
(To:Werner_E)

A better approach:

4-Participant
(To:Werner_E)

Does this apply to all symbolic evaluation? It seems I run into this problem every once in a while when I define an equation symbolically and solve it for a certain variable and then use the resulting solution. It does however work sometimes so it seems to me as if symbolic equations are able to deal with units. Is there any explanation to this?

24-Ruby V
(To:mlavery)

The symbolic doesn't know anything about units and treats them as unknown variables. If you havee an expression created by the symbolic which only contains units as "unknowns" and evaluate it numerically you again see the units as it should be.

4-Participant
(To:Werner_E)

But as far as I can see that is what I did. I did assign each variable a numerical value with a unit, but the I still get an error, or is there a fundamental difference between what I did and your example?

24-Ruby V
(To:mlavery)

The reason seems to be because LambertW is a symbolic only function. As it does not know anything about units it does not simplify A*Ohm to Volt and so can't cancel it in the exponent. That way LambertW is not able to show a numeric result and so can't the numeric.

24-Ruby V
(To:mlavery)

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):

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(....) :

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

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 III
(To:mlavery)

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

Success!
Luc

7-Bedrock
(To:LucMeekes)

Dear Luc,

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

Thanks

Walter

23-Emerald III
(To:WalterSchrabmai)

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

Try if it runs after you change that.

Success!
Luc

7-Bedrock
(To:LucMeekes)

Thanks, yes that was the reason. Now it works also with your MC11-version.

Here your MC11 for MC15, with the Lambert Equivalent.

21-Topaz II
(To:mlavery)

Hi,

Announcements