#include #include #include using namespace std; /* Lentilles simples */ double pos_image(double l, double f, double x){ double xp; xp = 1./f + 1./(x-l); xp = l + 1./xp; return xp; } int main(){ double u, F, d, f, y1, y2, g; int i, imax; fstream fich; f = 20.; d = 500.; F = 50.; imax = 1000; fich.open("lentilles_py.res", ios::out); for (i = 1; i <= imax; i++){ u = (d/imax)*i; y1 = pos_image(u,F,0.); g = -(y1-u)/u; y2 = pos_image(d,f,y1); g = -g*(y2-d)/(d-y1); fich << u << " " << y2-d-f << " " << 10*g << endl; } fich.close(); ostringstream pyth; pyth << "A = loadtxt('lentilles_py.res')\n" << "plot(A[:,0], A[:,1], label='y(u)')\n" << "plot(A[:,0], A[:,2], label='grandissement * 10')\n" << "plot(A[:,0], 0*ones(len(A[:,0])), label='0')\n" << "plot(A[:,0], 2*ones(len(A[:,0])), label='2')\n" << "ylim(-30,30)\n" << "xlabel('u')\n" << "legend(loc=9)\n" // mettre la legende en haut au milieu ; // On pourrait rajouter une ligne "help(legend)\n" pour voir les possibilites make_plot_py(pyth); return 0; }