[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 118 KB, 1152x907, nebula_rcw49_04lrg.jpg [View same] [iqdb] [saucenao] [google]
3025619 No.3025619 [Reply] [Original]

I just bought Wolfram Mathematica. Long time user of Wolfram|Alpha, new to Mathematica. Could someone point me to tutorials, and more specifically how can I make projects that aren't notebooks or presentations but printable (sort of like digital notes). I also need to be able to draw (geometry, physics and whatnot) and include formulas with special symbols. Also some chemistry required.

Thanks in advance. Pic unrelated

>> No.3025633
File: 1.24 MB, 2389x3000, cutey_Emma_Waat.jpg [View same] [iqdb] [saucenao] [google]
3025633

inb4 Josef

>> No.3025658

You should become familiar with the keyboard shortcuts, otherwise writing formulas is awful.
Ctrl+...
2 -> square root
6 -> superscript
7 -> above-script
5 -> "other position", for example when you're writing in superscript, 5 will move you to the subscript cell
It's also very handy to define a button for double brackets [[ ]] since you'll be using those a lot, it's quicker to type, and way easier to read.
_ -> subscript
/ -> fraction
Space -> jump out of the current cell to the next higher order (i.e. typing it while you're in the numerator will move the cursor after the whole fraction)

Next step: Learn the escape commands.
esc int esc results in an integral, esc dd esc in a differential d, so to write <span class="math">\int_a^bx\mathrm dx[/spoiler] you type esc int esc ctrl+_ a ctrl+5 b ctrl+space x esc dd esc x
The vast majority of symbols can be entered this way, there's usually a section "the symbol XY may be entered as ESC blabla ESC" in the help.

>> No.3025670

>I also need to be able to draw
Forget it. I mean you can draw, but that's not what the program was made for. Drawing in Mathematica means entering all coordinates by hand, i.e. you'll be sitting hours until all lines have the correct position and shape.

>> No.3025702

>>3025658
sup josef, in jersey yet?

>> No.3025710

Thanks for the help, Josef. Also how can I enter pictures (made with other programs) and how can I input equations ? I can't find the option, since I don't want them computed, but not plain text either.

>> No.3025729

>3025702
I'll fly mid august, be patient :)

>>3025710
>enter pictures
Use Import[], e.g. Import["/home/josef/foo.jpg"].
>how can I input equations
You mean something like <span class="math">x^2=4[/spoiler]? Just like in C++, the "equal" operator is == in Mathematica, so type x ctrl+6 2 ctrl+space ==4. (You can write it as x^2==4 as well, but the first version is a lot more readable).
To solve the equation, use Solve[], e.g. Solve[<span class="math">x^2==4[/spoiler],x].

>> No.3025754

I meant how to input formulas, without actually computing them. Like I would write in my psyhics notebook g=G/m . Stupid example, but you get the point.

>> No.3025782

>>3025754
You'll have to enter the text environment for that. I'm sure you have noticed the brackets on the very right side of the notebook already, those actually say something (although it's really shitty to see).
When you start typing, you're always in Input mode. Now move your cursor somewhere below so it's a long horizontal line (or just press ctrl+end to move to the very end of the nb), then select Format|Style|Test in the top menu. This opens a new cell that takes text rather than Mathematica code. Inside such a text environment, you can open a formula environment by typing ctrl+9 (notice the change in background color; to exit this mode again, use ctrl+space or ctrl+0). Here you can type your usual formulas now, such as ESC int ESC blabla dx.

>> No.3025784

>>3025782 Test
Supposed to be Text

>> No.3025800

Thanks alot for the help. Anything else I should know or any other tips ?

>> No.3025821

- When you feel the urge to use While, For or Do, you're probably writing shitty Mathematica code.
- Lists are the fundamental data object in Mathematica, and most of the functions are built to work with them.

- Look up Function in the help, very handy to have.

- Make sure to get the difference between = and := early, because they're a bitch to debug if you've written your code without caring and then have to find the error.

- Don't use %. If you use it, make sure the code section doesn't matter (it's ok for quick tests etc)

>> No.3026415
File: 217 KB, 2100x1722, carrie-fisher.jpg [View same] [iqdb] [saucenao] [google]
3026415

>>3025821
explain the difference between := and = please.

And what's that stuff with up/down-value?
I read the explaination a view times but I don't get it..

>> No.3026590

>>3026415
a = b
... calculates b, and assigns the value to a, like in any other programming language.
a := b
... does not calculate b right away. However, every time a is encountered, b is inserted and calculated in-place.

For example, execute this code:
a = RandomReal[];
{a,a,a,a,a,a,a,a,a,a}
b := RandomReal[]
{b,b,b,b,b,b,b,b,b,b}

The first list will have identical elements, the 2nd one different ones every time.

It's hard to explain when to use = and :=, it's really a matter of experience when to use which one. In most cases it's obvious, but sometimes there are really awful mistakes emerging from a mixup.

For a beginner, I'd say = assigns variables, while := defines function-like things (although using Function[] is the better way to go)

On up-/downvalues, maybe have a look at Shifrin's book, "Mathematica programming", free ebook via Google.
I'll try explaining it briefly:
:= defines a replacement pattern. f[a] := b creates a rule for f such that when it is used with an argument a, b is inserted.
^:= (UpSetDelayed) also defines a replacement pattern, but this time the property is assigned to a, not f.
Unfortunately I don't have an example in mind when this ever mattered to me. I'm sure you can use it for some nifty programming, but I haven't gotten that far yet.

>> No.3026698

>>3026590
Ah, another up/downvalues thought I just had.
Say you defined Del[] to be some derivative, let's say
Del[f_[x_]] := D[f[x],x]
(In practice I can imagine this could be handy for divergence-free functions etc.)
(btw, Del[f] can be entered as ESC del ESC f)
Now you want to define a function that has zero derivative everywhere.
You could of course say
Del[somefunction[x]] := 0
but that wouldn't really be the right assignment, since it's not a property of Del that applied to somefunction it yields 0 - it's a property of somefunction that is has zero derivative (zero divergence in the more complex case).
So what you'd be using here would be
somefunction :/ Del[somefunction[x]] := 0
or alternatively, a bit less readable,
Del[somefunction[x]] ^:= 0


Another example: Redefine built-in functions.
Say you want to make sure that a+1 is 2. Typing
a+1:=2
won't work however, since addition cannot be redefined, it's protected by Mathematica (since changing it might mess up the whole system with unforseeable side effects).

If however you define this operation not to be a property of + (which is Plus[] by the way), but of a, the assignment works:
a /: a+1 := 2
a+1
-> output: 2

>> No.3026778
File: 39 KB, 313x480, 859890_PK49.jpg [View same] [iqdb] [saucenao] [google]
3026778

>>3026698
Okay, thank you very much, I get your drift.

>> No.3026789

>>3026778
If you find a good example on when to use upvalues because it really matters for some reason please let me know.
I'm not sure whether it's just semantics or has some significant application.

>> No.3026806

>>3026789
I have used them before, let me look a sec.

>> No.3026842
File: 1.14 MB, 1920x1200, cutey_emma_stone_1920_1200_may152009.jpg [View same] [iqdb] [saucenao] [google]
3026842

1/3

\[ScriptN] /: \[ScriptN][1] := 1
\[ScriptN] /: \[ScriptN][x_] \[ScriptN][y_] := \[ScriptN][x y]

\[ScriptP][x_] := \[ScriptN][x] /; Element[x, Complexes]
\[ScriptP][x_ y_] := \[ScriptN][x] \[ScriptP][y] /;
Element[x, Complexes]
\[ScriptP][\[ScriptN][x_]] := \[ScriptN][x]
\[ScriptP] /: \[ScriptP][\[ScriptP][x_]] := \[ScriptP][x]
\[ScriptP] /: \[ScriptP][x_] \[ScriptP][y_] := \[ScriptP][x y]
\[ScriptP] /: \[ScriptP][x_ \[ScriptP][y_]] := \[ScriptP][x y]
\[ScriptP] /: \[ScriptP][x_ + \[ScriptP][y_]] := \[ScriptP][x + y]
\[ScriptP][\[ScriptN][x_] y_] := \[ScriptN][x] \[ScriptP][y]
\[ScriptP][\[ScriptN][x_] + y_] := \[ScriptP][x + y]

>> No.3026852
File: 390 KB, 800x1198, cutey_Emma_Schirm.jpg [View same] [iqdb] [saucenao] [google]
3026852

2/3

dropnp[var_] := Simplify[Times @@ Map[
\!\(\*SubscriptBox["#",
RowBox[{"\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]]\)^
\!\(\*SubscriptBox["#",
RowBox[{"\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]]\) &,
Select[FactorList[#], Not[FreeQ[First@#, var]] &]]] &

np[var_] := Simplify@Times[
\[ScriptN][
\!\(\*SubscriptBox[
RowBox[{"FactorTermsList", "[",
RowBox[{"Simplify", "[", "#", "]"}], "]"}],
RowBox[{"\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]]\)],
Times[
\[ScriptP][Simplify[Times @@ Map[
\!\(\*SubscriptBox["#",
RowBox[{"\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]]\)^
\!\(\*SubscriptBox["#",
RowBox[{"\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]]\) &,
Select[#, FreeQ[First@#, var] &]]]],
Simplify[Times @@ Map[
\!\(\*SubscriptBox["#",
RowBox[{"\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]]\)^
\!\(\*SubscriptBox["#",
RowBox[{"\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]]\) &,
Select[#, Not[FreeQ[First@#, var]] &]]]
] &[FactorList[
\!\(\*SubscriptBox[
RowBox[{"FactorTermsList", "[",
RowBox[{"Simplify", "[", "#", "]"}], "]"}],
RowBox[{"\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]]\)]]
] &

>> No.3026858
File: 273 KB, 650x371, mollywhat.png [View same] [iqdb] [saucenao] [google]
3026858

3/3

(* Bem: Man muss bei func und par keinen Test machen ob der Imput \
womöglich leer ist weil gilt: Times@@{}=1 *)

mapnp[var_][output_] := Simplify@Map[np[var], Expand[output]]
mapdropnp[var_][output_] := Simplify@Map[dropnp[var], Expand[output]]


f = 3 x^2 + 6 Sin[x]

dropnp[x]@f
np[x]@f
mapnp[x]@f
mapdropnp[x]@f

>> No.3026869

Thanks, 4chan messed up the line breaks but I think I'll manage to get what ... wait, no. What does the code do? It's easier to ask in the first place.

>> No.3026873
File: 237 KB, 936x1400, cutey_Emma_genau.jpg [View same] [iqdb] [saucenao] [google]
3026873

?/4

It's a running eater of overal factors (I was bored)

>> No.3026876

What's a running eater?

>> No.3026903
File: 58 KB, 383x655, Bild 2.png [View same] [iqdb] [saucenao] [google]
3026903

I could seperate or kill numerical factors during calculations with it

anyway, the point is I used /: for
\[ScriptN] /: \[ScriptN][x_] \[ScriptN][y_] := \[ScriptN][x y]

>> No.3026916
File: 31 KB, 338x321, Bild 4.png [View same] [iqdb] [saucenao] [google]
3026916

>> No.3026935
File: 12 KB, 347x147, Bild 5.png [View same] [iqdb] [saucenao] [google]
3026935

es ist schon ziemlich geil wie einfach sowas mit Mathematica geht ;)

>> No.3026938

(Ah, you're the sexy@ guy hehe)

Gotta go now, should've gone to bed way earlier anyway. Thanks for the code man, I'll look through it tomorrow, hoping to find out what
p /: p[p[x]] := p[x]
does, since it seems a bit redundant to me (p appears twice, how does /: handle that?), I would have left the p /: away.
That program looks handy as a garbage collector for differential equations and such, "just plug everything into the constant and let the program keep track of it".

>> No.3026966
File: 46 KB, 802x1113, cutey_Emma_Calassy.jpg [View same] [iqdb] [saucenao] [google]
3026966

>p /: p[p[x]] := p[x]

Ich hab relationen von n mit p und wenn steht p[p[30]], dann erkennt n das p nichtmehr etc.
drum, wenn steht

p[p[3]], dann soll er einfach p[3] schreiben

Ich bin gleichzeitig auch "Algebra Guy", du hast meine email ;)

>> No.3026976

(und ja, bei mir isses demnach auch gleich 1)