problem Derivative in C++

Write your question here.
I have a project for school and the teacher gave us an old book, in which is the program needed is: Elliptic equations. Finite difference method.I tried to write the code in c++ from that old language. I expect it to be with errors. The problem is that I am a begginer and I tried to look on the internet but I can't find a method in c++ that I understand.

I don't know how to write the functions.
Example: u-ecuation solution
d^2u/dx^2+d^2u/dy^2=4;
u(0,y)=y^2;
u(1,y)=1+y^2;
u(x,0)=x^2;
u(x,1)=x^2+1;
h=k=1/4;

It would be a great help if someone can tell me what is missing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  Put the code you need help with here.

#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
using namespace std;

//functions?

int main(){
float U[100][100],F[100],x;
int i,j,m,n,a,k;

 ifstream f("Text.txt");
    f>>n;

	for(i=1;i<=n;i++)
           for(j=1;j<=i;j++)
			f>>U[i][j];
        for(i=1;i<=n;i++)
             f>>F[i];

	for(j=1;j<=n;j++){
	U[1][j]=0;
	U[j][1]=0;
	U[n][j]=0;
	m=n-1;
	   for(k=1;k<=n;k++){
		   a=m;
		   x=(k-1)/a; 
 F[k]=x*(1-x)/2;
		   }
	   for(i=2;i<=m;i++){
	   U[i][2]=(F[i-1]+F[i+1])/2;
	   }
	   for(j=2;j<=m;j++){
		   for(i=2;i<=m;i++){
		   U[i][j+1]=U[i-1][j]+U[i+1][j]-U[i][j-1];
		   }
	   }
	}
for(i=1;i<=n;i++,cout<<" "){
	for(j=1;j<=n;j++){
				
			cout<<U[i][j];
	 }
}
}
         
Topic archived. No new replies allowed.