Tag Info

1

And another completely different approach is to use LinearSolve Clear[c1, c2, x, y] eqs = {c1*x + c2*y == 1, -c1*x + 2*c2*y == -2}; vars = {c1, c2}; {b, mat} = CoefficientArrays[eqs, vars]; LinearSolve[mat, -b]

1

Another option: vars = {c1, c2}; eqs = MapThread[{#1*x + #2*y == 1, -#1*x + 2*#2*y == -2} &, Map[List, vars]]; Solve[First@eqs, vars]

1

cv = Array[ c , 2 ] Solve[ { cv[[1]] x + cv[[2]] y == 1 , -cv[[1]] x + 2 cv[[2]] y == -2} , cv] {{c[1] -> 4/(3 x), c[2] -> -(1/(3 y))}} cv /. First@% {4/(3 x), -(1/(3 y))}

2

Since qIndoor + qOutdoor + qField + qVeg == 400000 there are only three independent variables alphaIndoor = 1.46172*10^6; alphaOutdoor = 1.61956*10^7; priceTap = 977.554; alphaField = 2.41546*10^7; alphaVeg = 547723; eqns = {(qIndoor/alphaIndoor)^(-10/3) - (qOutdoor/alphaOutdoor)^(-4/3) == 0, (qOutdoor/alphaOutdoor)^(-4/3) - priceTap - ...

1

FindRoot[{(qIndoor/alphaIndoor)^(-1/0.3) - (qOutdoor/ alphaOutdoor)^(-1/0.75) == 0, (qOutdoor/alphaOutdoor)^(-1/0.75) - priceTap - (qField/alphaField)^(-1/1.5) + 30 == 0, (qField/alphaField)^(-1/1.5) - (qVeg/alphaVeg)^(-1/0.5) == 0, qIndoor + qOutdoor + qField + qVeg == 400000}, {{qIndoor,100}, {qOutdoor, 100}, {qField, 100}, {qVeg, 100}}] {qIndoor ...

1

sol = (x /. Solve[Sin[x] == 1/10, x]); sol2 = Minimize[{#, (# > 0)}, C[1], Integers] & /@ sol {{Pi - ArcSin[1/10], {C[1] -> 0}}, {ArcSin[1/10], {C[1] -> 0}}} Min[sol2[[All, 1]]] ArcSin[1/10]

6

Ok, at first you don't solve your equation properly, the grid spacing is not enough for the entire time range. So first increase resolution, e.g.: tmax = 10; mdfun = NDSolveValue[ {D[h[x, t], t] + D[h[x, t]^-1*D[h[x, t], x], x] + D[h[x, t]^3*D[h[x, t], {x, 3}], x] == 0, h[0, t] == h[2 Sqrt[2] \[Pi], t], h[x, 0] == 1 + 1/10*Sin[x/Sqrt[2]]}, h, {x, 0, ...

1

This question relates to nonlinear wave steepening and I see now that I did not list everything that was necessary to address the problem. I am also quite certain that I phrased this question poorly on account of my novice-level experience with NDSolve in Mathematica. The question spawned from my attempt to reproduce results from this paper. On the ...

4

A system with approximate (Real) coefficients sometimes has only approximate solutions. Minimizing the norm of the residuals, approach 3 below, may be the best way to approximate the solutions. In this case, we have seven equations in six unknowns. equations = { β1 - (β2 β3)/α1 == 0.1867, α2 - (β3 β3)/α1 == 1.9867, α3 - (β2 β2)/α1 == 0.9867, ...

2

NSolve can deal primarily with polynomial systems. In this problem one can easily eliminate the exponential term from the gradient of f. Since stationary point conditions depend only on directions of gradients and not on their magnitudes, one can divide gradients by nonzero functions. scaledgradf = Grad[y E^(x - z), {x, y, z}]/E^(x - z); gradg = Grad[9 x^2 ...

1

If I understand you correctly: f[n_, t_] := Select[{#, Eigenvalues@#} & /@ Tuples[{0, 1}, {n, n}], MemberQ[#[[2]], t] &][[All, 1]] But be careful because the tuples thing grows ... quickly :). Finding an efficient way is more complicated.

3

f[y_] = y Exp[(x - z)] /. Solve[ 9 x^2 + 4 y^2 + 36 z^2 == 36 && x y + y z == 1, {x, y, z}] // Simplify // Quiet; cons = List @@ Reduce[ Cases[f[y], Sqrt[t_] -> t, Infinity][[1]] > 0, y]; ptsMax = {y /. #[[2]], #[[1]]} & /@ (Outer[NMaximize[{#1, #2}, y] &, f[y], cons, 1] // Flatten[#, 1] &) ...

4

1

I found it easier to create explicit polynomials. \[HBar] = 6.5821192815/10^16;(*this is hbar/e*); c = 3*10^8;(*Velocity of light in vacuum,in m.s^-1*) kappaR = {kp1, kp2, kp3}; omegaR = {or1, or2, or3}; poly = Numerator[ Together[ k^2*c^2 - (omega^2*(1 + Sum[4 Pi kappaR[[i]]/(1 - omega^2/omegaR[[i]]^2), {i, 1, 3}]))]]; npoly ...

2

Concerning the follow-up question in a comment: ...just for curiosity, if someone knows how to impose a positive codomain to not yet known function, I would very much like to know. One way is to define the system so that x'[t] is positive whenever x[t] < 0. Then when x[t] reaches 0, it will be stuck at 0, unless x'[t] becomes positive for x[t] > ...

5

Well, both $(1-x)$ and $(x-2)$ evaluate to $-1/2$ when $x\rightarrow 3/2$, and Log[-1/2] its well defined in the complexes, for instance $e^{iπ}= −1$, implies that $\ln(−1)=i π$, and therefore Log[-1/2]= I π - Log[2] so you are subtracting two well defined identical complex numbers to get zero. Therefore, this solutions does really solve the original ...

3

As mentioned in the comments, Mathematica is assuming a complex valued logarithm (and hence can take negative inputs). If you query this on Wolfram Alpha (here) you can see the pod clarifies the solution is assuming this complex valued logarithm:

0

I posted the solution I found in another thread (Constraining function found by NDSolve to stay positive) and I am reposting it here for convenience. However, in your particular case the model is not complete and you need to ensure that x'[t] is identically zero when x[t]<0. Here is your model with the necessary completion. The description is below. ...

1

As the comments already say, Sqr is not the function for squaring an expression, but you can easily define it yourself if you like Sqr[x_] := x^2 After this, your code gives the expected result p1tx = p1x + v1x*t; p1ty = p1y + v1y*t; p1t = p1xt + p1yt; p2tx = p2x + v2x*t; p2ty = p2y + v2y*t; p2t = p2xt + p2yt; dt = Sqrt[Sqr[p2tx - p1tx] + Sqr[p2ty - ...

3

Even if there is some kind of mistake (typo) the solution is to use WhenEvent with Sow and Reap: {sol, {pts}} = Reap@NDSolve[{x''[t] == x[t]/(2*Sqrt[x[t]^2 + (1 - y[t])^2]), y''[t] == -0.2 - (1 - y[t])/Sqrt[x[t]^2 + (1 - y[t])^2], x[0] == x'[0] == Pi/3, y[0] == y'[0] == 0.5, WhenEvent[y[t] == 0 && y'[t] > 0, Sow[{t, x[t]}]]}, ...

3

eq = {x[7] == 0, 6 x[4] x[5] + 6 x[3] x[5] x[6] + z*x[4] x[7]^2 + z*x[4] x[5] x[7]^2 == 0} Solve@FullSimplify[And @@ eq] (* {{x[4] -> -x[3] x[6], x[7] -> 0}, {x[5] -> 0, x[7] -> 0}} *)

2

An additional option, that might not be known (I did not know about this until Daniel mentioned this on another post), is that if one have an idea about the range of values of the variable being solved for, and possibly other parameters, then NSolve and Solve will now be able to find solutions. At least from the examples I've tried so far f = ...

2

If you only need a numerical solution, then FindRoot should be one option: FindRoot[f, {x, 4}] (* {x -> 6.91844} *) and Plot[f, {x, 0, 10}, Epilog -> {Red, PointSize[.03], Point[{x, f}] /. FindRoot[f, {x, 4}]}]

1

I get no errors from your code after correction of \\ to //: ODE = H u2''''[x] == Subscript[p, 0] SpringBC = -H u2''[L] == k u2'[L] {u2} = {u[x]} /. DSolve[{ODE, 0 == u2[0], 0 == u2'[0], 0 == u2[L], SpringBC}, u2, x][[1]] // Simplify H (u2^(4))[x]==Subscript[p, 0] -H (u2^\[Prime]\[Prime])[L]==k (u2^\[Prime])[L] {u[x]} Please clarify your ...

3

1

You need to increase the MaxRecursion: f = (-b + Sqrt[b^2 + 4 a])/(2 a); g = (-b - Sqrt[b^2 + 4 a])/(2 a); RegionPlot[{ Reduce[Abs[f] > 1 && Abs[g] > 1 && Im[a] == 0 && Im[b] == 0 && Re[b^2 + 4 a] >= 0, a, Complexes], Reduce[Abs[f] > 1 && Abs[g] > 1 && Im[a] == 0 && ...

1

Start by using Eliminate to remove the parametric variable Eliminate[{x == 1 - t^2, y == t - 2}, t] -3 - 4 y - y^2 == x Now you can Solve to get an expression of the form $y(x) = -2 \mp \sqrt{1 - x}$ sol = (y /. Solve[-3 - 4 y - y^2 == x, y]) {-2 - Sqrt[1 - x], -2 + Sqrt[1 - x]} To sketch you will need to know where it crosses the axis sol ...

1

I think you might be looking for this. eqs = {x == 1 - t^2, y == -2 t - 2}; eq1 = Eliminate[eqs, t] (-4 - y) y == 4 x ContourPlot[Evaluate@eq1, {x, -20, 2}, {y, -12, 12}] eq2 = {x, y} /. (And @@ eqs // ToRules) {1 - t^2, -2 - 2 t} fig = ParametricPlot[eq2, {t, -5, 5}, MeshStyle -> Directive[Opacity[0.5], Red], Mesh -> ...

1

New users see the word Solve and tend to think that is THE answer to ALL their problems. Solve is usually OK for polynomial problems and often not good for more complicated problems. Unfortunately the errors and warnings from Solve don't clearly direct you to a better method for the particular kind of problem that you just gave it. Reduce is sometimes more ...

4

It's pretty straightforward to make this work, so I'll just post my interpretation of what you're trying to do. In addition to neglecting to define the velocities and accelerations in terms of the positions, you also had some typos in there (capital XX etc.). There was also a redundant initial condition for XX[td] that I removed. It's important to define the ...

0

The reason your first block of code doesn't work is that you make the replacement for theta3 after invoking NSolve on the system of equations. At the time it is invoked, the system of equations doesn't have a numerical value for theta3 to work with. So you simply have to change the last line as follows (copying the whole first code block for consistency): ...

1

Given a matrix: eta = ({{1, 0}, {0, -1}}); one can decompose this into three matrices in the following way: {u, w, v} = SingularValueDecomposition[eta]; (* Where the original eta is defined by: *) u.w.Transpose[v] (* = eta *) Another way, which more appropriately addresses your problem is to use Schur decomposition. eta = ({{1, 0}, {0, -1}}); {q, t} ...

1

Another approach is to include a double-angle identity in the transformations tried by Simplify: doubleangle = # /. t_ArcTan :> 1/2 Simplify@ArcTan[TrigExpand@Tan[2 t]] &; Simplify[ Solve[Cos[x] - b Sin[x] == 0 && x > 0 && x < π && b > 0, x], TransformationFunctions -> {doubleangle, Automatic}] (* {{x -> ...

2

Belisarus in his comment gave one solution which can be referred to as a post-processing. Here is the pre-processing as you mentioned: eq = Cos[x] - b Sin[x] == 0; Map[Divide[#, Cos[x]] &, eq] // Expand (* 1 - b Tan[x] == 0 *) In my version 10, however, your equation is perfectly solved by itself yielding Solve[eq,x] (* {{x ...

1

You can also try Flatten[solutions][[All,2]]

1

Given a matrix mat replace the 0s in mat with an expression that depends on the indices. randommatrix = RandomInteger[1, {6, 6}]; randommatrix // MatrixForm MapIndexed[# /. {(0) -> Quiet@Style[Evaluate[diff2 @@ #2], Red], _ :> 0} &, randommatrix, {2}] // MatrixForm mat = 1 - Unitize[tttt2]; args = Table[{w, Pprobe}, {w, 2.5, 3., 0.1}, ...

7

In addition to what I wrote in the comment, you can get a result much faster if you avoid using the explicit eigenvalues. Their product is the constant term of the characteristic polynomial so use that instead and rearrange the last equation as needed. M = {{α1, β3, β2}, {β3, α2, β1}, {β2, β1, α3}}; Timing[ sol2 = NSolve[{ β1 - (β2 β3 )/α1 == 2/3, ...

1

I post this as another answer (using again $3p3=p1+p2-5$) if the matrices are the main aim: sa0 = SparseArray[{i_, j_} :> (i - 1) (j - 1), {3, 3}] // MatrixForm; sa = SparseArray[{{i_, j_} /; ((i - 1) (j - 1) != 0) :> (i - 1) (j - 1), {i_, j_} /; ((i - 1) ( j - 1) == 0) :> (i + j + 5)/3.}, {3, 3}] // MatrixForm; Row[{sa0, ...

2

Your p3 definitions seem different. The following uses 3p3 -5=p1+p2. set = Tuples[Range[0, 2], 2]; set /. {x_, y_} :> (x + y + 5)/3. /; x y == 0 yields: {1.66667, 2., 2.33333, 2., {1, 1}, {1, 2}, 2.33333, {2, 1}, {2, 2}} or if you wish to couple results and {p1,p2}: set /. {{x_, y_} :> Rule[{x, y}, (x + y + 5)/3.] /; x y == 0, {x_, y_} :> ...

3

For your second question, you could use (tabletry = Table[p1*p2, {p1, 0, 2}, {p2, 0, 2}]) // MatrixForm; (* or (tabletry = Array[# #2 &, {3, 3}, 0]) // MatrixForm; *) (tst = Map[{# == 0} &, tabletry, {-1}]) // MatrixForm or (tst2 = Array[# #2 /. {0 -> {True}, _ -> {False}} &, {3, 3}, 0]) // MatrixForm Note the parantheses wrapping ...

3

I guess you are looking for this. Solve[x1 == !x2 && x2 == !x1, x1] // Quiet {{x1 -> ! x2}} I transpose Unequal to Not Equal like following code. Solve[x1 != !x2 && x2 != !x1 /. a_ != b_ :> (!a) == b, x1] // Quiet {{x1 -> x2}}

3

Unless I'm misunderstanding your question, I think its worth pointing out that {{x1 -> x2}} is not a valid solution to your original equation. Indeed, if x1 == x2, then $$x_1=1-x_2=1-x_1$$ which is always false modulo 2. Mathematica's solution {{x2 -> 1 - x1}} is correct since the two original equations are not linearly independent, and thus ...

1

delay = 4*10^-9; gamma = (25*10^3)/0.511; beta = Sqrt[1 - gamma^-2]; c = 3*10^8; rho = lb/theta; drift = 4 lb; time = (4 rho*theta + 2 drift - 4 lb - 2 drift*Cos[theta])/(beta*c); disp = lb^2/rho + lb/rho*drift*Cos[theta]; ContourPlot[{time == delay, disp == .6}, {theta, -12, 5}, {lb, 0, .3}, FrameLabel -> (Style[#, 14, Bold] & /@ {theta, ...

1

Updated answer: Thanks to hint by Daniel below, one can give NSolve region to search on. NSolve[{time == delay, disp == 0.6 && (-4 Pi < theta < 4 Pi) && (0 < lb < 10)}, {theta, lb}] gives {{theta -> -10.6056, lb -> 0.108685}, {theta -> -8.28907, lb -> 0.105523}, {theta -> -3.97865, lb -> 0.089839}, ...

4

This is a bit long for a comment. You can use a tandem of LinearSolve and NullSpace. But for exact problems this will, I'm fairly sure, use dense matrices. That takes you back to what Solve is doing anyway, under the hood. Assuming your inputs are integer or rationals you might avoid dense matrix algebra as follows. Use numerical methods to find a single ...

2

sol = Flatten[Solve[{w^2*c^2 - 1 == 0, c == #}, {c, w}] & /@ {1, 2}, 1] {{c -> 1, w -> -1}, {c -> 1, w -> 1}, {c -> 2, w -> -(1/2)}, {c -> 2, w -> 1/2}} sol == Flatten[ Solve[{w^2*c^2 - 1 == 0, c == #}, {c, w}] & /@ (c /. {{c -> 1}, {c -> 2}}), 1] True

6

Introduction My first suggestion is to learn a little more about optimization. A good tutorial can be found here from Wolfram: http://reference.wolfram.com/language/tutorial/ConstrainedOptimizationGlobalNumerical.html Analysis Now let's have a closer look at your problem. der1 = (a (0.50984 + 2.75322 b))/(0.0649842 + 0.70185 b - 0.871367 b^2)^2 ...

2

cc = {c -> 1, c -> 2}; sol = Solve[(w^2*c^2 /. #) - 1 == 0, w] & /@ cc; Partition[Riffle[Riffle[cc, cc], Flatten @ sol], 2] cc = {c -> 1, c -> 2, c -> 3}; sol = Solve[(w^2*c^2 /. #) - 1 == 0, w] & /@ cc; Partition[Riffle[Riffle[cc, cc], Flatten @ sol], 2]

6

I like this short one: Solve[w^2 c^2 - 1 == 0 && (c == 1 || c == 2), {w, c}] (*{{w -> -1, c -> 1}, {w -> 1, c -> 1}, {w -> -(1/2), c -> 2}, {w -> 1/2, c -> 2}}*) It can be generalized as: cvalues = {1, 2, 5, 6}; Solve[w^2 c^2 - 1 == 0 && Or @@ Thread[c == cvalues], {w, c}]

3

ArrayReshape[Tuples /@ ({#, Solve[(w^2*c^2 /. #)-1 == 0, w]} & /@ {{c -> 1}, {c -> 2}}), {4, 2}] or Partition[Flatten[Tuples /@ ({#,Solve[(w^2*c^2 /. #)-1 == 0, w]} & /@ {{c -> 1}, {c -> 2}})], 2] both give (* {{c -> 1, w -> -1}, {c -> 1, w -> 1}, {c -> 2, w -> -(1/2)}, {c -> 2, w -> 1/2}} *)

Top 50 recent answers are included