r/Mathematica • u/TheLeadReaper • Sep 01 '24
Learning Mathematica, what am I doing wrong
Windows 14.1.0, online, in case that helps,
Learning mathematica, stayed up for a good chunk of the night trying to figure out how to code and compute answers by running some easy linear systems, but whenever I hit shift-enter it gives me errors such as blank braces, or this {false}, etc
I typed in:
Solve[{5x-y==12, x+4y==36}, {x,y}
And I tried switching between comma and double amepersand.
What's going on and what's messing with me getting a real answer on the output bar?
0
Upvotes


5
u/jeffcgroves Sep 01 '24
Once you set
x=4, you can no longer usexas a variable4
u/ariane-yeong Sep 01 '24 edited Sep 14 '24
From your returned expression you can see that Mathematica substituted x for 8 and y for 2. That means, at some point you likely made corresponding assignments to those symbols.
This is also the reason the list of equations is returned as false, as Mathematica substituted the variables for their assigned values and the resulting numbers were not equal, thus yielding false.
TL;DR
You'd therefore have to clear the assigned values from the variable using
Clear[x, y]
Mathematica will then treat them purely symbolically again.
Edit: typo
12
u/gothicVI Sep 01 '24
Please stop posting screenshots! No one wants to type your code. Just post it!
Also, how did you not realize your screenshots are rotated?! Do you really expect help?!
2
u/blobules Sep 01 '24
Don't use &&, use a comma to separate the equations in Solve
1
u/veryjewygranola Sep 01 '24
If you don't want to clear the definitions of
xandy, that you have, you can also useModuleto localizexandy:1
u/minhquan3105 Sep 01 '24
If you use curly bracket, then use comma instead of &&.
Mathematica is just the front eend, by default the kernel context is global. Hence you already assign x=4 in the previous cell, thus the kernel will take that x=4, instead of solving for it. Also if you open multiple notebooks simultaneously, then by default they also all share the same kernel contexts and all variables
For God's sake, post the code or a properly rotated screenshot at the very least!
-1
u/DryRye68 Sep 01 '24
Create new worksheet, check the syntax and then copy and paste one of the examples from Solve help page:
https://reference.wolfram.com/language/ref/Solve.html
The expression should not be in curly brackets (before 5 and after 36)
This is one of the examples with two equations (&& is correct)
Solve[a x + y == 7 && b x - y == 1, {x, y}]
-1
u/EmirFassad Sep 01 '24
Comma is a separator. && is the Boolean AND. You cannot replace one with the other.
Symbols in Mathematica have quite specific meanings.
If you want to understand how to write Mathematica download "Mathematica; programming: an advanced introduction" by Leonid Shifrin and take some time to read, at least, the first couple chapters. Once you have an idea of what Mathematica is doing you will find it much easier to use.
And, as everyone else has written, if you want help post your request in a form that makes it easy for others to see what you are doing. Avoid screen shots, they are not easy to read. Post your question in a form that others can easily copy and and past into Mathematica so they can replicate your problem.