Hot answers tagged

15

Description In software engineering, it is a good practice to comment your code. I would advise you to utilise comments to partition your code in a following way. Additionally, if you have ever worked with any other programming languages, you could employ indentation. Alternatively, you could modularize your application as to develop it in smaller, more ...


12

Personally, I use lots of newlines and let the Front End indent. There doesn't seem to be anything special in your code, other than a lot of nesting that is in fact necessary in this case. You were using Grid incorrectly. Grid[a,b] is wrong. Grid[{{a,b}}] or Grid[{{a},{b}}] are correct. I guess you wanted Column[{a,b}], so I changed that. Using Text ...


9

I appear to be in the minority but I never write big blocks of Mathematica code, it's just too difficult to read. The way I look at it you have to consider how a reader will understand your app. So I make the main block very small, like this: Manipulate[ Row[{ vectorPlotAndTrajectory[y0, b], Show[fy, position[y0, b]] }] , {b, -7.99, 8} , {{y0, 2}...


6

Here is the way it would look if it were my code.My formatting style is much the same as Szabolcs' (including replacing your grid with a column), but I don't like his dangling ], and you won't see those. Also, I always start control specifications on a new line, and I mostly start option specifications on a new line, too. Note: I have redefined ϕ to ...


5

The result returned by WeatherData[] is a TimeSeries[] object. ListPlot[] can deal with it directly, but LinearModelFit[] needs some assistance to handle it, since it cannot directly deal with either TimeSeries[] or Quantity[] objects. Thus: trendLine = LinearModelFit[theTemps["Path"] // QuantityMagnitude, x, x] Show[ListPlot[theTemps, AxesLabel -> {"...


3

How about adding some assumptions (I think the following is reasonable): res = Integrate[(x1 + x2 - 1)*(Boole[ x1 + x2 >= s && x1 >= t1 && x2 >= t2]), {x1, 0, 1}, {x2, 0, 1}]; FullSimplify[res, 0 < s < 1 && 0 < t1 <= t2 < 1] $$\begin{cases} \frac{1}{2} (\text{t1}-1) (\text{t2}-1) (\text{t1}+\text{...


2

Your 2nd attempt is closer to something that's useful. Let's rewrite it with valid Mathematica syntax. lissajous[{a_, b_, c_, d_}] := ParametricPlot[{Re[E^(I a t) E^(I b t)], Im[E^(I c t) E^(I d t)]}, {t, 0, 2 Pi}, Axes -> False] Then DynamicModule[{u = RandomInteger[10, 4]}, Column[ {Dynamic@lissajous[u], Button["Run", u = ...


1

Is this a "standard" Manipulate which will not grow larger? Ok, use one of already posted answers. Here is an alternative in case where Manipulate is supposed to be generated from a package function or is a part of a bigger code. ClearAll["Test`*"]; BeginPackage["Test`"] myManipulate::usage = "myManipulate[] generates a demo Manipulate"; Begin["`...


1

To help you get started: func[a_, b_, ϕ_] := Exp[(I a ϕ) + (I ϕ])^b] ParametricPlot[{Re[func[1, 1, ϕ]]], Im[func[1, 1, ϕ]]]}, {ϕ, 0, 2 Pi}] a = 1; b = 1; c = 1; d = 1; ParametricPlot[{Re[Exp[(I phi)^a + (I phi)^b]], Im[Exp[((I phi)^c + (I phi)^d)]]}, {phi, 0, 2 Pi}]



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