# Tag Info

## Hot answers tagged homework

33

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 ...

16

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 ...

13

In Mathematica: Integrate[Integrate[x^2 + y^2, {x, -Sqrt[1 - y^2], Sqrt[1 - y^2]}], {y, -1, 1}] Or, shorter: Integrate[x^2 + y^2, {y, -1, 1}, {x, -Sqrt[1 - y^2], Sqrt[1 - y^2]}] The main trick is to calculate the bound on $x$ based on the current value of $y$, which is what you need to make the integration bounds explicit. Indeed, $x_{max}=\sqrt{1-y^2}$. ...

12

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_}}]:= ...

12

You have some errors in your syntax: you name your lists x_sample and y_sample, but in Mathematica, an underscore is not allowed in names (as it is reserved to patterns). your last sum runs from 0, but in Mathematica, the first element in a List has index 1 your last sum should run until the number of data points, not 4 furthermore, I would advise you to ...

11

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 ...

10

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 . ...

10

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). ...

9

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

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 ...

8

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, ...

8

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)$ ...

8

Your formula should be either 4 + Sum[(-1)^x*4/(2*x + 1), {x, 1, Infinity}] Pi or Sum[(-1)^x*4/(2*x + 1), {x, 0, Infinity}] Pi The finite series approximation is then Clear[f] f[n_] := Sum[(-1)^x*4/(2*x + 1), {x, 0, n}] As n increases, f[n] converges slowly to Pi. With[{nmax = 150}, DiscretePlot[f[n], {n, 1, nmax}, Epilog -> {Red, ...

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}, ...

7

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, ...

7

Using your code, let me make it clear by introducing an auxiliary function that sums the exponents in an expression sortFunc[expr_] := Total[Exponent[expr, x, List]] Now you can go with Sort[mylist, sortFunc[#1] < sortFunc[#2] &]

7

I may not be understanding the question correctly, but if you wish to show the stream field under solutions, perhaps this is a method: Manipulate[ Module[{soln}, soln = Quiet@ DSolve[{y'[x] == -Cos[y[x]]/Sin[x], y[x0] == y0}, y[x], x]; Show[ StreamPlot[{1, -Cos[y]/Sin[x]}, {x, -4, 4}, {y, -4, 4}, StreamColorFunction -> "Rainbow", ...

6

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 ...

6

Using defaults values _. (for multiplication it is 1) works: {Sinh[3 Q] + Sinh[Q]} /. Sinh[a_. Q] -> (x^a - x^-a)/2

6

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)$ ...

6

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, ...

6

This is quite common a problem when doing nonlinear fit. As far as I know, the most general and effective solution for it is to give the fitted parameters a good enough start value, which you've already known for your specific problem: exp = c/(1 + ((c - n)/n)*E^(-r*t)); FindFit[points, exp, {{c, 256}, {n, 9}, r}, t] Show[Plot[exp /. %, {t, 7, 84}], ...

6

Here is a direct approach: digitsum = Composition[Total, IntegerDigits]; stubbornQ = PrimeQ[#] && Nor @@ PrimeQ[digitsum[#] - {1, 2, 3, 0, -1}] &; i = 1; While[! stubbornQ[++i]] i 8999 This was quite sufficient in this case. For larger search spaces see Iterate until condition is met. A bit more efficient for v10+ using NoneTrue for ...

6

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}], {#, ...

6

The recurrence equation can be solved analytically Clear[a] a[n_] = a[n] /. RSolve[ {a[n + 1] == 3 a[n] + 7, a[1] == 6} , a[n], n][[1]] (1/6)*(-21 + 19*3^n) Generate a sufficiently long starting list, Select numbers that do not contain the digit 5, and Take the first five elements of the remaining list. Take[ Select[ Table[{n, ...

6

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 ...

6

This question was largely dealt with in the comments. I post this for illustrative purposes (but mainly fun): The following shows use of PoissonProcess and its use with RandomFunction, Expectation, Probability. The last line is probability at t=6 that there had been only 1 customer for rate 5/hour: pp = PoissonProcess[5]; rf = RandomFunction[pp, {0, 6}, ...

5

I can say with certainty that, as of version 9, it is not possible to set the degrees of freedom for PearsonChiSquareTest. I recommend seeing my answer here for an implementation of your own test that allows you to bin your own data.

5

Basically you have to plot 4 equations [$\pm y^2 = b(x\pm a);\pm x^2 = b(y\pm a)$]. So try to get the roots of them first. {s11[s_, x_], s12[s_, x_]} = y /. Solve[s y^2 == b (x + s a), y] {s2[s_, x_]} = y /. Solve[s x^2 == b (y + s a), y] Second one is linear in y, so only 1 root. $s=\pm 1$ which will give you different equations. $a,b$ are parameters to ...

5

Select is wrong in this case, you can't use it to get the n-th element of a list without using additional helper functions. You'll get the most out of this exercise by looking at Part, which is a very flexible function for extracting elements out of a list based on their position, for example x = {1,1,2,3,5,8,13,21,34,55} (* Explicit syntax. Extracts the ...

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