|
プログラム作りましたが、これではうまくグラフが描けませんでした。
つまり、刻み幅が30で書くために、私はグラフを陽側から推測してニュートン法で解きました。が、先生は陰側からグラフを推測すれば刻み幅が30でも滑らかな曲線が描けるそうです。しかし、陰側からの推測して解くプログラムが分りません。分る方教えてください。また、このプログラムで間違いがあれば指摘の方もお願いします。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "chinougl.h"
#define EXP 2.718281828
#define SC 0.8
void mdeul(int n, double x0, double y0, double xn);
void gr(int i, double x, double y);
typedef struct{
double fnc;
double dfn;
}FV;
double c=1.0;
int main(){
int i,n=30;
double x0=0.0,y0=0.0,xn=1.0;
mdeul(n, x0, y0, xn);c++;
//for(i=0;i<n;n++){x[i]=x0;y[i]=y0;}
gotogl();
return 0;
}
FV fn(double x, double y, double z){
FV ff;
ff.fnc=z-pow(EXP,0.01/(pow(x-0.5,2)+0.002))+5.0*pow(EXP,y);
ff.dfn=1;
return ff;
}
double F(double x, double y){
int n=0,nmax=30;
double er,e=1.0e-6;
static double z=0.0;
static int k=0;
FV func;
do {
func=fn(x,y,z);
er=func.fnc/func.dfn;
z=z-er;
n++;
}while(fabs(er)>e && n<nmax);
if(n==nmax)
gotogl();
k++;
return z;
}
void mdeul(int n, double x0, double y0, double xn){
int i;
double x,xp,y,yp,h;
x=x0;
y=y0;
h = (xn - x0) / n;
for(i=0;i<n;i++){
yp = y + F(x, y) * h;
xp = x + h;
y += (h / 2) * (F(x, y) + F(xp, yp));
x += h;
gr(i,x*SC,y*SC);
}
return;
}
void gr(int i, double x, double y){
static double xo,yo;
if (i){
line(xo/2-1*SC,yo/2*SC,x/2-1*SC,y/2*SC);
switch((int)c){
case 1: color(0,0,1);break;
case 2: color(1,0,0);break;
case 3: color(0,1,0);break;
case 4: color(1,1,1);
}
}
xo=x;
yo=y;
|