Skip to content

Instantly share code, notes, and snippets.

@Corwinpro
Created November 5, 2013 16:13
Show Gist options
  • Save Corwinpro/7321464 to your computer and use it in GitHub Desktop.
Save Corwinpro/7321464 to your computer and use it in GitHub Desktop.
#define _CRT_SECURE_NO_DEPRECATE
#include "stdio.h"
#include "math.h"
#include <iostream>
using namespace std;
int a = 998;
int b = 1998;
int c = -999;
int d = -1999;
//явный метод расходится
/*double V(double Vn, double Un, double h)
{
return (Vn*(1/h + d/2 + c*b/(2*(1/h-a/2))) + c*Un*(1/2+(1/h+a/2)/(1/h-a/2)))/(1/h-d/2+b/(2*(1/h-a/2)));
}
double U(double Vn, double Un, double h,double Vn1)
{
return Un*(1/h+a/2)/(1/h-a/2) + b/(2*(1/h-a/2))*(Vn+Vn1);
}*/
double V(double Vn, double Un, double h)
{
return (Vn*(1-a*h) + c*h*Un)/((1-d*h)*(1-a*h)-c*b*h*h);
}
double U(double Vn, double Un, double h,double Vn1)
{
return (Un+b*h*Vn1)/(1-a*h);
}
void main()
{
FILE * file = fopen("file.txt", "w");
double u = 1.0;
double v = 1.0;
double prev_v;
double h = 0.0001;
for(int i = 1; i < 0.1/h; i++)
{
prev_v = v;
v = V(v,u,h);
u = U(prev_v,u,h,v);
fprintf(file,"%e %e %e\n",h*i, u,v);
}
fclose(file);
//getchar();
system("pause");
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment