# Tag Info

## Hot answers tagged homework

43

Mathematica wouldn't be much helpful if one applied only formulae calculated by hand. Here we demonstrate how to calculate the desired geometric objects with the system having a definition of the curve r[t] : r[t_] := {t, t^2, t^3} now we call uT the unit tangent vector to r[t]. Since we'd like it only for real parameters we add an assumption to Simplify ...

20

Okay, let's focus on this snippet: Module[{i, j}, Do[ pe = (volume[[j, i + 1]] pi[[j, i + 1]] + volume[[j, i]] pi[[j, i]])/(volume[[j, i]] + volume[[j, i + 1]]) //. Indeterminate -> "*" // Quiet, {i, 1, 8, 1}, {j, 1, 10, 1}]] Creating some dummy data: volume = RandomReal[{-1, 1}, {10, 9}]; pi = RandomReal[{-1, 1}, {10, 9}]; ...

18

Manipulate[MatrixPlot[Table[Mod[i + j, 2], {i, 1, n}, {j, 1, n}], ColorFunction -> "Monochrome"], {{n, 8}, 1, 20}] Nice and simple. To make it a little more terse we can use Array in place of Table: Manipulate[MatrixPlot[Plus ~Array~ {n, n} ~Mod~ 2, ColorFunction -> "Monochrome"], {{n, 8}, 1, 20}] With correct column numbering, thanks to a ...

17

The dimensional phase-space plot The analysis of the predator-prey model is incomplete without the phase-space plot. So, here it is, a = 2/3; b = 4/3; c = 1; d = 1; sol[x0_?NumericQ] := First@NDSolve[{x'[t] == a*x[t] - b*x[t]*y[t], y'[t] == c*x[t]*y[t] - d*y[t], x[0] == x0, y[0] == x0}, {x, y}, {t, 0, 20}]; ParametricPlot[Evaluate[{x[t], y[t]} /. sol[#] &...

14

From Weierstrass Approximation Theorem we know there is such a polynomial, moreover there are infinitely many polynomials satisfying given criterion. Therefore we would like to find those ones of the minimal order. Since we are supposed to exploit series approximations we define a polynomial of n - th order approximating 6 ArcTan[x] for x such that (-(1/...

13

I assume (sorry if I'm being wrong) that this is some kind of homework. So I've written an answer as guidance. You'll have to work out some details. If your problem is three dimensional, you can write for example: dist[x0_,x1_] := (x0-x1).(x0-x1); power[x0_,x1_]:= c/dist[x0,x1]; findAnt[{{pow1_,pos1_},{pow2_,pos2_},{pow3_,pos3_}}]:= ...

13

Observe that even when the tangent vector $r'(t)$ is not normalized, it is still a linear combination of $T(t)$ and $N(t)$. Thus--operating under the usual assumptions that $r'$ and $r''$ exist and are linearly independent--all we have to do is make an orthonormal frame out of $r'(t)$ and $r''(t)$ (which is very much in the spirit of the entire proceeding). ...

12

Mathematica 10 provides new functionality dealing with curves, (see e.g. the Vector Analysis tutorial) like ArcLength, ArcCurvature and especially FrenetSerretSystem: FrenetSerretSystem[{ x1, ..., xn}, t] gives the generalized curvatures and Frenet-Serret basis for the parametric curve x[t] i.e. it returns {{ k1, ..., k(n-1)}, { e1, ..., en}}, where ki ...

12

For even n: MatrixPlot[ ArrayPad[DiagonalMatrix[{1, 1}], 3, "Reflected"], PlotTheme -> "Monochrome"]

12

This code presented in this answer is essentially the same as the code given by DumpsterDoofus. I just want to point out the importance of having meaningful values for the parameters and initial conditions. I also want to show one might explore the parameter space with a Manipulate expression. One of the phenomena demonstrated by the Lotka-Volterra model is ...

11

I'm not too good at graphs, but this seems straightforward. myAdjacencyMatrix = {{0, 3, 1, 3, 3, 8, 0, 0, 3, 4, 2}, {1, 0, 2, 0, 0, 16, 5, 3, 0, 6, 1}, {2, 3, 0, 0, 1, 1, 4, 1, 1, 0, 0}, {5, 3, 3, 0, 5, 0, 2, 2, 2, 2, 1}, {1, 0, 0, 6, 0, 1, 2, 6, 10, 2, 4}, {0, 11, 3, 0, 1, 0, 8, 3, 1, 3, 3}, {2, 4, 1, 7, 6, 7, 0, 6, 0, 8, 2}, {1, 2, 1, 3, 8, 4, 4, 0, ...

11

Taylor polynomials of order n aren't necessarily the nth degree polynomials that optimally approximate a function on a given interval. We can use linear least squares to find the optimal polynomials for a fixed n. inn[f_, g_, x_] := Integrate[f g, {x, -1/Sqrt[3], 1/Sqrt[3]}] LeastSquarePolynomial[f_, x_, n_] := With[{pows = x^Range[0, n]}, pows . ...

11

Anyone asking you to write For loops in Mathematica for such a problem is a dolt. Nevertheless, here's how you might do that: rslt = 0; For[i = 0, i <= 50, i += 2, rslt += i]; rslt And here's how someone with some familiarity with Mathematica might write it Plus @@ Range[25]*2 Now, spend the time you were going to waste writing a For loop by reading ...

11

You could try NDSolve then ParametricPlot3D Manipulate[ Module[{a = 0.25, b = 0.5, ode1, ode2, ode3, x, y, z, t}, ode1 = x'[t] == -y[t] - z[t]; ode2 = y'[t] == x[t] + a y[t]; ode3 = z'[t] == b + z[t] (x[t] - c); sol = NDSolve[{ode1, ode2, ode3, x[0] == x0, y[0] == y0, z[0] == z0}, {x[t], y[t], z[t]}, {t, 0, maxTime}, MaxSteps -> Infinity]; ...

10

r = ParametricRegion[{r Cos[ϕ], Sin[ϕ] r, Sqrt[28 r]}, {{r, 0, 21}, {ϕ, 0, 2 π}}] Area[r] 49/2 π (14 Sqrt[3] - ArcSinh[Sqrt[3]])

9

The symbol $\epsilon$ is called the Levi-Civita tensor, it is usually written in terms of its components $\epsilon_{i j k}$. Having defined two vectors (i.e. first order contravariant tensors): a = { a1, a2, a3}; b = { b1, b2, b3}; we have to build up a tensor product of two vectors and Levi-Civita tensor, i.e. we get a new tensor of valence $(3,2)$ (i.e....

9

We can find a 7th order polynomial that meets the requirement if we minimise the $\infty$-norm. For simplicity I construct an array of {x, 6 ArcTan[x]} over the required range and plug it into FindFit, no doubt there are better ways. {a, b} = {-1, 1}/Sqrt[3]; data = Table[{x, 6 ArcTan[x]}, {x, a, b, (b - a)/1000.}]; n = 7; expr = Sum[c[i] x^i, {i, 1, n, 2}];...

9

You forgot to specify initial conditions on $x$ and $y$, which makes plotting impossible. However, even when initial conditions are specified, DSolve seems to choke on some sort of inverse-function garbage, so I'll sidestep it by using NDSolve instead (I'll let others determine why the analytic solution doesn't work): {a, b, c, d} = {1, 2, 3, 4}; {X, Y} = ...

9

This is just a suggested amendment to JasonB's answer. It wasn't clear to me that it deserves a separate answer, since it deals with side issues tangentially related to the OP's question. It's easier to deal with the singularities if we scale the direction field by Sin[x]. Since only one streamline needs updating when the initial condition is changed, we ...

9

You can use MeshFunctions to visualize the intersection. The following is one way to parametrize curve. f[x_, y_] := 2 x^3 - 5 y^4; p[x_, y_] := x + y + 5; expr = x /. Quiet[First@Solve[f[x, y] == p[x, y], {x, y}, Reals]]; t[u_] := expr /. y -> u; par[w_] := {t[w], w, p[t[w], w]}; p3D = Plot3D[{f[x, y], p[x, y]}, {x, -20, 20}, {y, -10, 10}, ...

9

Clear["Global*"] f[a_?(# > 0 &)] := Module[{x, m = 1}, x[0] = 1.; x[n_] := x[n] = (x[n - 1] + a/x[n - 1])/2; While[x[m]^2 != a, m++]; x[m]] f[#] - Sqrt[#] & /@ {2, E, Pi, Prime[17]} (* {-2.22045*10^-16, 0., 0., 4.26326*10^-14} *) A more straightforward method of recursion is to use FixedPoint Clear["Global*"] f[a_?(# > 0 &)] ...

8

My answer: cb[n_Integer /; n > 0] := MatrixPlot@SparseArray[{i_, j_} :> Mod[i + j, 2], {n, n}] cb[8] For those who desire a more traditional board: Block[{n = 8}, MatrixPlot[ SparseArray[{i_, j_} :> Mod[1 + i + j, 2], {n, n}], ColorFunction -> GrayLevel, FrameTicks -> { {#, #} &@ Table[{i, n - i + 1}, {i, n}], {#, #} &...

8

You'll learn more trying to understand the following code than by programming silly Do[ ]s startA = 0; startT = 1000; velA = 10; velT = 9; pos[start_, vel_, time_] := start + vel time tf = t /. First@Solve[pos[startA, velA, t] == pos[startT, velT, t]]; Plot[{pos[startA, velA, t], pos[startT, velT, t]}, {t, 0, tf}, AxesLabel -> {Time, Position}, ...

8

Copying your exact code de1 = 25*Derivative[2][x][t] + 10*Derivative[1][x][t] + 226*x[t] == 901*Cos[3*t]; inits = {x[0] -> 0, Derivative[1][x][0] -> 0}; DE = LaplaceTransform[de1, t, s] X = Solve[DE, LaplaceTransform[x[t], t, s]] X = Last[Last[Last[X]]] X = X /. inits f1 = Simplify[Expand[InverseLaplaceTransform[X, s, t]]] Now it's easy to ...

7

If you want to translate Matlab code into Mathematica, my advice is - don't! As programming languages, the two are very different and an idiom that works well in one is unlikely to work well in the other. A fundamental theorem theorem in discrete dynamics states that if there's an attractive orbit, then it must attract at least one critical point. Thus, ...

7

This is mainly an answer to your last question, but I think it will help with your other ones. I assume you know that the $T$ function is vector valued, and that is what you want. To substitute in a specific value of $t$, you probably want replacement rules, specifically the ReplaceAll (/.) construct. For example, if you had defined your expression $T(t)$ ...

7

Graphics[{{Green, Line[{{0, 0}, {1/Sqrt[2], 1/Sqrt[2]}}]}, {Red, Line[{{1/Sqrt[2], 0}, {1/Sqrt[2], 1/Sqrt[2]}}]}, {Line[{{0, 1/Sqrt[2]}, {1/Sqrt[2], 1/Sqrt[2]}}]}, {Green, PointSize[.03], Point[{1/Sqrt[2], 1/Sqrt[2]}]}, {Circle[{0, 0}, 1, {-2 Pi, 2 Pi}]}}, Axes -> True, Ticks -> {{0, 1/Sqrt[2]}, {0, 1/Sqrt[2]}}]

7

If you really want a parabola primitive from 3 points, you can use Fit to fit a parabola to the three points, Plot to plot it, and Cases to extract the Line primitive from the plot. For example parabola[pts_] := Module[{x, func, xmin, xmax}, func = Fit[pts, {1, x, x^2}, x]; xmin = Min[pts[[All, 1]]]; xmax = Max[pts[[All, 1]]]; Cases[Plot[func, {x, ...

7

You can use a LocatorPane to edit the control points (at least in 2 dimensions) and see the curve change in real time: pts = RandomReal[{-1, 1}, {5, 2}]; LocatorPane[Dynamic[pts], Dynamic[Graphics[ { BSplineCurve[pts], Dotted, Line[pts] }, PlotRange -> {{-1, 1}, {-1, 1}}]]] If you play around with the points a little, getting a pretzel ...

Only top voted, non community-wiki answers of a minimum length are eligible