C++ code for finding any value of the levi civita tensor

Sup Jow Forums
I am a 1st year physics major and am learning how to code in C++.Given that I have no background in computer programming, I suck balls.Any who,I made this code to calculate the values of the levi-civita pseudo tensor.For those who dont have a phsics background, you can think of it as a function ϵ(i,j,k), that takes in integer inputs of 3 variables i,j,and k which can only be 1,2 and 3 and gives an output of 1,0 and -1. 1 when (i,j,k)=(1,2,3),(2,3,1),(3,1,2),0 if any of the two variables have the same value and -1 for (i,j,k)=(3,2,1),(2,1,3),(1,3,2).
I finished the loop and everything but it wont budge and i've been stuck at this for a while now. Can someone tell me what I'm doing wrong or suggest an alternative that doesnt involve making a class or setting up the all the inputs 1 by 1.

Attached: Screenshot (178).png (1366x768, 88K)

Other urls found in this thread:

lmgtfy.com/?q=code indentation
en.cppreference.com/w/cpp/algorithm/is_permutation
en.cppreference.com/w/cpp/algorithm/next_permutation
twitter.com/NSFWRedditVideo

compare equal is == not =

Attached: 1527689442657.jpg (960x1440, 411K)

which line?

11, 15
there are several more errors.

You don't have to do that in C++, just do it in Matlabs, or Scilab if your uni doesn't have you covered with Matlab license.
If you really want a programming language, you should check Python, it has everything you need.
Any of these abiove would me way more easier than C++.

summer, this is not firstly, fix your indentation/format
secondly, remove last if "statement"
lastly, delete your existence

why in god’s name did you try doing this in c++???

first of all, the levi-covita symbol is built into mathematica and sympy. second of all, if you want to do coding of stuff like this for fun, you’d avoid hitting your head against the wall like this if you used python. i recommend jupiter notebooks for you.

third of all, you should be able to mentally do permutations of three indices. don’t be that guy who uses a TI-89 to calculate sin(pi/6)

t. physics phd student

i wish i was doing this for fun, this is an assignment that I was given as an exercise in c++

Fix your indentation and I might consider helping you because this just looks just like bait

is this really what fucking physics phd students work on?

I dont know what that is,
we're taught by rote

Yeah sure go fuck yourself baiter, who would ever give an assignment in C++ without telling people what fucking indentation is

Im doing 1st year Honors, not Phd
and at this rate I wont be

is this what you meant?

Attached: Screenshot (179).png (1366x768, 87K)

holy shit this retard again

line 15, you have ; inside the else statement, remove it.


also, fix your indentation, choose tab/2 or 4 spaces and indent all text after a { to the right for each level, and go back for each }

lmgtfy.com/?q=code indentation

Now this got me wondering how to check for permutations in an elegant way in C or C++. In Matlab I'd just do some logic wizardry with vectors but that probably won't fly anywhere else. Fuck Matlab is so goddamn easy.

Why do physics/math guys always program like this.

No indentation, single letter variable names, and overall inelegant expressions.

top bait OP and Jow Forums fell for it because they are ubuntu c++ coders lmao

en.cppreference.com/w/cpp/algorithm/is_permutation
en.cppreference.com/w/cpp/algorithm/next_permutation

int main() {
int i, j, k, l, e;

cin >> i >> j >> k;

for (i = 1; i

change line 15 to
else eijk=-1;
The error is that you are using parenthesis instead of curly braces.
Also, reformat using Astyles included with Code::Blocks

Try indenting your code. This is so fucking hard to read

I'm pretty sure it's because
Eulers_number ^ (Archimedes_constant imaginary_unit) = -1 is sooo much easier to remember than single symbols. Not.

Except if the symbols have different meanings elsewhere, but well, we can use different alphabets and accents to differentiate.

Hmmm, I wonder when the first mathematical constant will be written with an emoji character.

Because everything they do is a throwaway prototype and not an actual product.

Your code is really bad but I guess for a freshman "physics major" its not horrible.
fix your indentation (as in actually indent your code)
give better variable names (self-identifying)
also your algorithm isn't entirely effiecient, and I also don't understand why you recieve input into i,j, and k, but then overwrite that data in the definition of your for loops
for(i =1;...) sets i to 1 even though it could have been something else entirely a moment ago.
I also dont understand why you're checking it up to 27 times (O(n^3) algorithm) when you only need to check it once by what you've said in the OP
I'm being very critical as you have asked for help in something you have very little knowledge in, next time post it in the /sqt/ thread or

Attached: horrible code.png (501x354, 25K)

>No indentation, single letter variable names, and overall inelegant expressions.
Because they're given a single programming class; typically in C++ that only teaches them basic language syntax and they don't practice on their own.

how does Jow Forums like this implementation?

this is an implementation of how i would do it "mentally", but probably more optimized would be to do it with the "case" keyword...

#include
#include
#include

int main(int argc, char * argv[]){
if (argc != 4) {
std::cout

>Jow Forums does some pseud's homework again

>atoi(argv[iArg]) > 4
oops. that should be a 3, not a 4.

compiled and ran it, but it gives the wrong output

Attached: Screenshot (186).png (1366x768, 94K)

I like it, the code reads pretty well and I was able to understand what you were doing at a glance

also should have added a check that no two indices are the same

What is the program even trying to do? You want to test the property for i, j, k which you want to read from standard input?
But then you immediately rewrite them in for-loops and test it for all combinations of i, j, k in [1...3]. That program is total bullshit and does nothing.

1) learn to fucking indent your code
2) be clear of what the task it
3) put logic out of main(), you can make a function int LeviCivita(int i, int j, int k) that doesn't care where you read the variables from
4) main() function now consists of reading the values and calling the function with logic

int LeviCivita(int i, int j, int k) {
if (i == j || j == k || k == i) {
return 0;
}
if ((i == 1 && j == 2 && k == 3) ||
(i == 2 && j == 3 && k == 1) ||
(i == 3 && j == 1 && k == 2)) {
return 1;
}
return -1;
}

int main() {
int i, j, k;
cin >> i >> j >> k;
cout

for (int i = 1; i < 4; ++i) {
for (int j = 1; j < 4; ++j) {
for (int k = 1; k < 4; ++k) {
int order = (j-i)*(k-j)*(i-k);
std::cout

You're really stupid OP

Why do compsci guys - who must fundamentally rely on mathematics to accomplish anything - generally suck at math?
Because it's not the focus of your study.

At least you guys actually make money, as long as you aren't outsourced by an H1B.

this outputs gibberish for me, plus even if i fix it like so:

for (int i = 1; i < 4; ++i) {
for (int j = 1; j < 4; ++j) {
for (int k = 1; k < 4; ++k) {
int order = (j-i)*(k-j)*(i-k);
std:: cout

how can you be good at math and not understand how to program a fucking computer

yea, i forgot a -1. multiply order by -1.

taste comes from practice, same as in every field

So, ϵ(i,j,k) = -signum((j-i)(k-j)(i-k))

Attached: vlcsnap-2018-06-27-11h55m31s013.png (574x515, 215K)

This problem is easy to solve, but it would be fun to try to come up with a really elegant solution. It seems that this user: is on to something. The question then is how to generalize to an arbitrary number of dimensions.

i think using cyclic permutations and swaps like this post
easily generalized to higher dimensions

Mathematics is beautiful.

>cout

Is this a serious question?

What the fuck is that indentation, you pillock? I'm pretty sure every ide including code::blocks auto-indents.

What in the fuck is actually wrong with you?

>Sup Jow Forums
>I am a 1st year physics major
no need to read that far

You fucking disgust me

Looks like the CS grad student meme code.

Please stop, there are domain specific languages for this stuff.
MATLAB
SciPy
hell, even GNU Octave
just to name a few.

what justification do you have to write this in C++, because the speed meme isn't going to matter
and it obviously isn't because you know how to program in C++ already.

Attached: 1530131754505.jpg (638x686, 79K)

Because only non autists care about things such as "readability" or "maintainability".

Personally I never comment anything in any of my programs, except for the outputs of previous runs, the only variable names I use are i,j,k,l for integers, A,B,C,M for Matrices and x,y,z for floats if I need more I just keep adding _ or I use cryptic abbreviations.

When I had to write a couple of test for some solver for linear system I literally just copy and pasted everything, which resulted in a 1000+ line file which did the same thing over and over again with slightly changed variables.

To be decent at programming you also need to know some best practices, tooling etc. That's not stuff that just knowing math or fundamental compsci stuff will help with.

>and not understand how to program a fucking computer
Mathematicians do, but sadly they don't write non-trivial code for brainlets to understand, which leads to these issues.

Because there's absolutely no reason to delve into anything more than general programming languages for simple matrix calculations, you dumb anime turd.

>Why do compsci guys - who must fundamentally rely on mathematics to accomplish anything - generally suck at math?
I've never seen a cs major who sucks at math.

>I've never seen a cs major who sucks at math.
Most CompSci majors can't even prove something as basic as Lagrange's Theorem, LMAO.

Attached: 1516308254092.jpg (645x729, 81K)

>Lagrange's Theorem
Let the man prove his own theorem, if he's so smart.

>physishit that can only into lingebra and anal so buttmad that CS chadpergers get to play with higher topoi
No idea where you went but on my uni, CS students took math with mathemagicians while physishits had their own classes. And they took much more abstract courses than physishits.

think he meant like this

int main (){
double a, b, c;
cout > a >> b >> c;
if (a > b && b > c) {
cout

D'oh. how do I codetext?

9 out of 10 CompSci majors can't solve this

Attached: x.png (380x48, 5K)

>Lagrange's Theorem
There's an analysis one and group theory. What did you mean?

>Implying you can solve the Navier–Stokes equation
Is it even known whether solutions even exist?

You're using = to compare two values, when you should be using == (= is assignment). You didn't indent your code (I'm surprised your IDE doesn't automatically do it for you). The last "else if" should just be "else". I haven't checked your actual logic but fixing these should at least make your program compile.

Yeah I'm sure OP would benefit from switching to python just to type in pretty much the same for loop. Besides, it's probably for some numerical methods course where they have to use C++, because implementing numerical stuff in the slowest language known to man would be a bit retarded.

>not directing OP to /sqt/ or /dpt/
>calling others summer

Take this, you seriously need it.

Attached: Tab-Key.jpg (333x212, 21K)

>t. brainlet
Yes, many solutions. Not all of them are smooth and that's the big issue with Navier-Stokes.
For 2-dimensional case, Navier-Stokes has been "solved" ages ago. For 3-dimensional case, there has been some progress by Tao, but it's far from answered.