# Tag Info

31

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

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

13

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

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

8

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

8

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

7

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

6

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

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

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

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

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

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

5

The quick answer is: AntennaPower[measure_List, antenna_List] := Module[{x1,x2,xa,ya,sd2}, {x1, x2, sd1} = measure; {xa, ya} = antenna; N[ sd1*(4*Pi*((xa - x1)^2 + (ya - y1)^2)/1000)] ] The point here is that the first argument to Module can only be a sequence of symbols (or of assignments x=x0,y=y0,...) but no expressions are allowed. Just an ...

5

How about m = Quantity[AstronomicalData["Earth", "Mass"], AstronomicalData["Earth", "Mass", "Units"]] 5.9721986*10^24 kg m // FullForm Quantity[5.9721985999999999999999999999999999999999202`8.*^24,"Kilograms"]

5

In this instance, I would make your Rounding function work just the way the built in Round function does, where it will thread over lists: Round[{1, 1.3, 0.5, 1.7, 2}] === {1, 1, 0, 2, 2} By adding the Listable attribute to Rounding you can accomplish the same thing: Attributes[Rounding] = {Listable}; Rounding[x_] := If[x - Floor[x] < 0.5, Floor[x], ...

5

You want to extract coefficients of terms in Cos[t] and other functions of t and find values of {A, B} that make these terms vanish. SolveAlways can do this sometimes (works reliably when input is polynomial, say). SolveAlways[ TrigExpand@{-2 Exp[t] ((A + 3 B) Cos[2 t] + (-3 A + B) Sin[2 t]) == Exp[t] Cos[2 t]}, {Sin[t], Cos[t]}] During ...

5

Here is another way to solve problems of this type: create a system of at least two independent equations for the two variables a and b. How to do this if you only have one equation to begin with? In your case one side of the equation (Exp[t] Cos[2 t]) is independent of the unknowns, so I just evaluate that side at some specific values of t and use those as ...

5

Similar to yet distinct from the other solutions. Substitute two values for t (not a period apart), to create two independent equations. Then you will get a unique solution. Solve[-2 Exp[t] ((n + 3 m) Cos[2 t] + (-3 n + m) Sin[2 t]) == Exp[t] Cos[2 t] /. {{t -> 0}, {t -> 1}}, {n, m}] (* {{n -> -(1/20), m -> -(3/20)}} *) (Of course, the ...

4

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

4

You can not assign to a list in local variable specification as You did {x1,x2,sd1}=measure. You can assign specific parts of dummy variables: AntennaPower[measure_, antenna_] := Module[{x1=measure[[1]], x2=measure[[2]], sd1=measure[[3]], xa=antenna[[1]], ya=antenna[[2]]}, N[sd1*(4*Pi*((xa - x1)^2 + (ya - y1)^2)/1000)] ] or use equivalent sebhofer's ...

4

freddieknets already told you what you're supposed to be doing. Here's how I'd have done your approach to least squares: n = 4; f[x_] = Map[C, Range[0, n]].x^Range[0, n]; Solve[Thread[ D[Total[(ysample - f /@ xsample)^2], {Map[C, Range[0, n]]}] == 0], Map[C, Range[0, n]]] // First // Chop {C[0] -> 0, C[1] -> 10., C[2] -> 0, C[3] -> 0, ...

4

If "diagnostics" or standard errors are required you can use NonlinearModelFit with the starting values: fun = c n/(n + (c - n) Exp[-r t]); nlm = NonlinearModelFit[points, fun, {{c, 256}, {n, 9}, r}, t] Visualizing fit: Show[ListPlot[points], Plot[nlm[t], {t, 0, 90}]] You can get model: nlm//Normal yielding 3213.19/(12.3092 + 248.73 E^(-0.0877072 ...

4

A heuristic way to narrow the search range is to assume that the common remainder is not too large, and hence that the ratios will not change by much. So set up three ratios for values minus remainder, and evaluate at remainder=0. fracs = Apply[Divide, Partition[vals - k, 2, 1, {1, -2}], {1}] nfracs = N[fracs /. k -> 0] (* Out[608]= {(1716 - k)/(2154 ...

4

f[t_] := UnitStep[t + 4] - UnitStep[t - 4] Plot[f[t], {t, -10, 10}, Exclusions -> None] You can use this like this also: Plot[Sin[t] f[t], {t, -10, 10}, Exclusions -> None, PlotRange -> All] Plot[5 f[t], {t, -10, 10}, Exclusions -> None, PlotRange -> All] etc...

4

You can also use LinearModelFit: lm = LinearModelFit[data2, {1, x}, x] You can 'normalize' output: Normal@lm This yields: -3.72168 + 0.663665 x You can look at underlying properties: lm["Properties"] yielding: {"AdjustedRSquared", "AIC", "AICc", "ANOVATable", \ "ANOVATableDegreesOfFreedom", "ANOVATableEntries", \ "ANOVATableFStatistics", ...

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