There this problem does not solve. There is an infinite loop and it looks to be as a result of line 20

#pragma once
#include<iostream>
#include<cmath>
#include<vector>

int analytical() {
using namespace std;
int i=0;
int j=0;
double arr[21][101];
int tsur = 300;
int tin = 100;
double D = 0.1;
double ssum=0.0;
for (j = 0; j <= 100; j++) {
for (i = 0; i <= 20; i++) {
for (int m = 1; 1 <= 40; m++) {
double x = ((i + 1)*0.05);
double t = ((j + 1)*0.01);
>>>LINE 20>>> double sum = (exp(-D*(pow(((m*3.14159) / 1.0), 2))*t)*((1 - (-1) ^ 2) / (m*3.14159))*sin((m*3.14159*x) / 1.0));
ssum = ssum + sum;
double ttot = tsur + 2 * (tin - tsur)* ssum;
arr[i][j] = ttot;

}
}
}
//print array
for (int j = 0; j <= 100; j++) {
cout << endl;
for (int i = 0; i <= 20; i++) {
cout << arr[i][j] << " ";

cout << "This is the analytical solution" << endl;

double ttot = tsur + 2 * (tin - tsur)* ssum;
return ttot;

}
}
}
Don't know about an infinite loop, but I think you'll find that
(-1)^2
doesn't do what you think it does ... and I couldn't see any reason for using it if it did. Also, division by 1.0 is a bit of a pointless operation: have you mistaken this for something else?

Please put your code in code tags, use consistent indentation, make sure that it has an int main() driving function, and change the magic number 3.14159 to a named constant PI.

It appears to be a double integral; perhaps you would like to point us to precisely what the integrand ought to be.
for (int m = 1; 1 <= 40; m++) {

This line will cause your code to loop forever. 1 is always <= to 40.
Topic archived. No new replies allowed.