# Define and solve formula syntax problem

Posted 6 months ago
1033 Views
|
7 Replies
|
4 Total Likes
|
 Hello,I some problems with the Mathematica syntax for defining and solving equationsI 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.20617*10^-6\ [Lambda]^2\ Log[6.57374*10^25\ \ [Lambda]]\ Z)[Z,[Lambda],T,x_] is Protected"
7 Replies
Sort By:
Posted 6 months ago
 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?
Posted 6 months ago
 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.20617*10^-6 [Lambda]^2 Log[6.57374*10^25 [Lambda]] Z)[Z,[Lambda],T,x_] is Protected. occurs with the output: \$Failed
Posted 6 months ago
 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.
Posted 6 months ago
 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] 
Posted 6 months ago
 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; Plot[Integrate[Kramer[12, 10.6, 30, x], x], {x, 0, 40}] I get SetDelayed::write: Tag Times in (5.20617*10^-6 [Lambda]^2 Log[6.57374*10^25 [Lambda]] Z)[Z,[Lambda],T,x_] is Protected. and the plot is empty
Posted 6 months ago
 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}]] 
Posted 6 months ago
 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.
Community posts can be styled and formatted using the Markdown syntax.