know the reason?
#include <iostream>
#include <cmath>
#include <cmath>
#include <fstream>
using namespace std;
int main ()
{
ofstream myfolder ("Rung-kutta-second order.txt");
double x1,x2,a,b,h,y1,y2,y,k1,k2,f1,f2,y_new,x0;
int n;
a=0; b=2;h=0.1;n=(b-a)/h; y1=b;
x0=a;
for (int i=1;i<=n; i++)
{
x1=x0;
f1=y1-pow(x1,2)+1;
k1=h*f1;
x2=x0+h;
y2=y1+k1;
f2=y1-pow(x2,2)+1;
k2=h*f2;
y_new=y1+(k1+k2)/2;
cout<<x2<<"\t"<<y_new<<endl;
myfolder<<x2<<"\t"<<y<<endl;
y1=y_new;
x0=x2;
}
myfolder.close ();
return 0;
}
I am not C++ guy but make sure that text file is in the directory. Plus it seems you didn't open the file.🤔🤔
I used myfile.open but it doesn't work either.
Didn't throw any execption?🤔
I don't know, every commands is correct I think
http://www.cplusplus.com/doc/tutorial/files/
I've read that page😅
Обсуждают сегодня