This is a manipulated schrondinger equation for quantum harmonic oscillator. And
ID: 3878116 • Letter: T
Question
This is a manipulated schrondinger equation for quantum harmonic oscillator. And the code need a to be in matlab or C++.
a) Write a short computer program that evaluates this integral numerically using the
trapezoid rule for any valid excitation state. Use only basic coding language functions:
arithmetic, loops, comparisons, exponentiation, and standard math functions such as exponentials, logarithms, and trigonometric functions. Attach all computer code and your coding must be commented and easy to understand.
(b) Report the probabilities for n = 0, 1, 2 from your program and discuss the trend as n
gets large. Use a sufficient number of integration points to achieve at least three decimal places of accuracy.
Explanation / Answer
#include<iostream>
#include<cmath>
using namespace std;
double cal(double x) // function to calculate the integral
{
double a=1/(1+x*x);
return a;
}
int main()
{
int n,i; //n is used for subintervals
double a,b,c,sum=0,in;
cout<<"Enter the limits of integration, Initial limit,a="; //to get the limits
cin>>a;
cout<<"Final limit, b=";
cin>>b;
cout<<"Enter the no. of subintervals, n=";
cin>>n; //accepting no of subintervals
double x[n+1],y[n+1];
c=(b-a)/n; //calculating width of the subintervals
for (i=0;i<=n;i++)
{ //here evaluation of x0 to xn and y0 to yn is done
x[i]=a+i*h; //and their value is stored in arrays
y[i]=cal(x[i]);
}
for (i=1;i<n;i++) //loop to evaluate c*(y1+...+yn-1)
{
sum=sum+c*y[i];
}
in=c/2.0*(y[0]+y[n])+sum;
cout<<"The definite integral is "<<in<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.