Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Computational Physics The programs should have self-explanatory comments and var

ID: 2268879 • Letter: C

Question


Computational Physics

The programs should have self-explanatory comments and variable names and proper indentation and the program should be written in C++. Please help me improve my own source code by adding on comments and modifying the program to make it cleaner and more efficient if possible. The Lev-Cevita function had to be created by reverse engineering and I want to know how to create a Levi-Cevita function that is correct. In other words, how do you create a Levi-Cevita in C++? Where did you find the source code and references?

(b) Devise at least three different test cases to verify your C++ program. Type your program on this website.

#include<iostream>
#include<stdio.h>
#include<math.h>

using namespace std;

//Levi-Cevita symbol function
int levi(int i, int j, int k)
{
//If i = j or i = k or j = k then Levi symbol is equal to 0
if((i==j)||(i==k)||(j==k))
return 0;
else
return ((i-j)*(i-k)*(k-j)/2);
}

int main(){

int val=0, i , j , k, l;
int AA[3][3]={{3,4,1},{2,1,2},{3,2,6}};

for(i=1 ; i<=3 ; i++){
for(j=1 ; j<=3; j++){
for(k=1 ; k<=3; k++){
//Compute the determinant of a 3 by 3 square matrix
det= det + levi(i , j , k )*AA[0][i-1]*AA[1][j-1]*AA[2][k-1];


cout<<i<<j<<k<<" : "<<levi(i,j,k)<<endl;
}
}

}

cout<<val<<endl;

return 0;
}

Explanation / Answer

In the program function for levi-cevita given.

The values of standard 3-dim levi-cevita are printed when run

value of detrminant of user defined matrix can be found

please comment if any query

//no need to use #include<iostream> stdio.h will be the standard input output library //

#include<stdio.h>

#include<math.h>

//no need using namespace std;

//Levi-Cevita symbol function

int levi(int i, int j, int k)

{

//no need to use If i = j or i = k or j = k then Levi symbol is equal to 0

//if((i==j)||(i==k)||(j==k))

//return 0;

return ((i-j)*(i-k)*(k-j)/2);//this equation will work fine

}

int main()

{

int i , j , k;

float det=0;

int MAT[3][3];// name of matrix is defined to be MAT and the elements will be input by user

for(i=1;i<=3;i++)

{

for(j=1;j<=3;j++)

{

for(k=1;k<=3;k++)

{

printf(" levi-cevita(%d,%d,%d)=%d ",i,j,k,levi(i,j,k));//this will print the value of all levi cevita

}

}

}

printf("enter elements of 3 by 3 matrix ");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

scanf("%d",&MAT[i][j]);//to input elements by user

}

}

printf(" ");

printf("matrix is ");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

printf("%d",MAT[i][j]);//to print matrix elements in matrix form

printf(" ");

}

printf(" ");

}

printf(" ");

for(i=0 ; i<2 ; i++)

{

for(j=0 ; j<3; j++)

{

for(k=0 ; k<3; k++)

{

//Compute the determinant of a 3 by 3 square matrix

det= det + levi(i+1 , j+1 , k+1 )*MAT[0][i]*MAT[1][j]*MAT[2][k];

}

}

}

printf("%f",det); //determinant will be printed

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote