schubert
(Karl S)
November 7, 2021, 1:56pm
1
Hello,
I some problems with the Mathematica syntax for defining and solving equations
I have following equations:
electrondensity[x_, Z_, Avog_] := (7*Avog*Z)/(118) * (1/x)^3
electrondensitycrit[\[Lambda]_] := 1.1 10^21/\[Lambda]^2
and try to solve them:
NSolve[electrondensity[x_, 12, Avog] == electrondensitycrit[10.6], x_]
This however works only if the underscores “" are used for the variable x
If “x” instead of "x ”, the solution is {}
Why is it? and why the following error message in case of “x_” appears? (but still solves the equation):
Solve::ratnz: Solve was unable to solve the system with inexact
coefficients. The answer was obtained by solving a corresponding exact
system and numericizing the result.
2nd question:
I want to define a formula:
Do I need to define the formula in this way? (indicating the variables?)
Kramer[Z_, \[Lambda]_, T_, x_] :=
108*10^-4 *Z *
Log[4*T/100 *\[Lambda]*2 \[Pi]/(0.577*6.626*10^-34 *3*10^8)]/((T/
100)^(3/2)*\[Lambda]^2 ) *((electrondensity[
x])/(electrondensitycrit[\[Lambda]]))^2
The error appears:
“Tag Times in (5.2061710^-6\ [Lambda]^2
Log[6.57374 10^25\ \ [Lambda]]\ Z_)[Z_,[Lambda],T ,x_] is
Protected”
This works well enough for me:
electrondensity[x_, Z_, Avog_] := (7*Avog*Z)/(118)*(1/x)^3
electrondensitycrit[\[Lambda]_] := 1.1 10^21/\[Lambda]^2;
Solve[electrondensity[x, 12, Avog] ==
electrondensitycrit[10.6], x, Reals]
It is somewhat tricky, because Mathematica may interpret the cubic root in the complex sense, while you may expect real values only. As for indicating the variables, it depends on what you want to do with the formula. Do you need only to display it, or for actual calculation?
Also, beware of the expression 4*T/100 *\[Lambda]*2 \[Pi].
Mathematica reads it as 4*(T/100) *\[Lambda]*2 \[Pi], which may not be what you have in mind.
schubert
(Karl S)
November 7, 2021, 3:37pm
4
Ok this works for me also now.
electrondensity[x_, Z_, Avog_] := (7*Avog*Z)/(118) * (1/x)^3
electrondensitycrit[\[Lambda]_] := 1.1 10^21/\[Lambda]^2
Konst[\[Lambda]_] :=
4*T/(100 *\[Lambda]*2 \[Pi])/(0.577*6.626*10^-34 *3*10^8)
I want to integrate the following formula for x:
Kramer[Z_, \[Lambda]_, T_, x_] :=
108*10^-4 *Z *
Log[Konst[\[Lambda]]]/((T/100)^(3/
2)*\[Lambda]^2 ) *((electrondensity[
x])/(electrondensitycrit[\[Lambda]]))^2
However, with defining this equation, the error:
SetDelayed::write: Tag Times in (5.2061710^-6 [Lambda]^2
Log[6.57374 10^25 [Lambda]] Z_)[Z_,[Lambda],T ,x_] is Protected.
occurs with the output: $Failed
I am getting no errors:
Kramer[Z_, \[Lambda]_, T_, x_] :=
108*10^-4*Z*
Log[Konst[\[Lambda]]]/((T/100)^(3/
2)*\[Lambda]^2)*((electrondensity[x, Z,
Avog])/(electrondensitycrit[\[Lambda]]))^2;
Integrate[Kramer[Z, \[Lambda], T, x], x]
schubert
(Karl S)
November 7, 2021, 3:54pm
6
Kramer[Z_, [Lambda], T , x_] :=
10810^-4 Z*
Log[Konst[[Lambda]]]/((T/100)^(3/
2)[Lambda]^2) ((electrondensity[x, Z,
Avog])/(electrondensitycrit[[Lambda]]))^2;
Plot[Integrate[Kramer[12, 10.6, 30, x], x], {x, 0, 40}]
I get
SetDelayed::write: Tag Times in (5.2061710^-6 [Lambda]^2
Log[6.57374 10^25 [Lambda]] Z_)[Z_,[Lambda],T ,x_] is Protected.
and the plot is empty
You must give a numerical value Avog and decide what function is Konst. Also, you must wrap Integrate in Evaluate, to avoid the trap of the order of evaluation:
electrondensity[x_, Z_, Avog_] := (7*Avog*Z)/(118)*(1/x)^3;
electrondensitycrit[\[Lambda]_] := 1.1 10^21/\[Lambda]^2;
Kramer[Z_, \[Lambda]_, T_, x_] :=
108*10^-4*Z*
Log[Konst[\[Lambda]]]/((T/100)^(3/
2)*\[Lambda]^2)*((electrondensity[x, Z,
Avog])/(electrondensitycrit[\[Lambda]]))^2;
Block[{Konst = Identity,
Avog = Quantity[1, "AvogadroConstant"] // QuantityMagnitude},
Plot[Evaluate[Integrate[Kramer[12, 10.6, 30, x], x]], {x, 0, 40}]]
Probably because of preexisting conflicting definitions. Quit the kernel and start over.
Integrate[Kramer[12, 10.6, 30, x], x]
(* -((7.42291*10^-42 Avog^2 (50.0099 + Log[T]))/x^5) *)
Avog and T do not have numeric values so a Plot cannot be generated.