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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

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

mlavery
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

The symbolic does not know anything about units.

How about this approach?

Werner_E_0-1583172672983.png

 

A better approach:

Werner_E_0-1583172908784.png

 

mlavery
4-Participant
(To:Werner_E)

Thank you for your reply! 

 

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?

 

 

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.

Werner_E_1-1584979913499.png

 

 

mlavery
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?

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.

Werner_E_0-1584993100461.png

 

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 😉

 

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

LucMeekes_0-1583182551595.png

Success!
Luc

Dear Luc,

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

Thanks

Walter

 

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

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

Here your MC11 for MC15, with the Lambert Equivalent.

 

-MFra-
21-Topaz II
(To:mlavery)

Hi,

answer4.jpg

Top Tags