Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
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!
The symbolic does not know anything about units.
How about this approach?
A better approach:
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.
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.
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):
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 😉
Attached is a Mathcad 11 file with an implementation of the LambertW 'function' that corresponds well with the symbolic equivalent:
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
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.
Hi,