inline void output_value_on_line(const std::string& filename, // Domain_<Float, Float, 2>& domain, // Axes aix, Float v, st idx) { //typedef Domain_<Float, Float, 2> Domain; typedef Domain_<Float, Float, 2>::pNode pNode; typedef Interpolate_<Float, Float, 2> Inter; typedef Point_<Float, 2> Point; typedef Expression_<Float, Float,2> Exp; // build an array st n = 300; ArrayListV<Float> arr = Linspace( // domain.grid().min(VerticalAxes2D(aix)), // domain.grid().max(VerticalAxes2D(aix)), n); // Interpolate ArrayListV<Float> arrval(n); std::fstream fss; fss.open(filename, std::fstream::out); for (st i = 0; i < n; ++i) { Point p; p[aix] = v; p[VerticalAxes2D(aix)] = arr[i]; pNode pn = domain.grid().get_pnode(p.x(), p.y()); Exp exp = Inter::OnPlane(pn, _X_, _Y_, p.x(), p.y(), 1); arrval[i] = exp.substitute(idx); fss << arr[i] << " " << arrval[i] << "\n"; } fss.close(); }
int main(){ int n = 6; int m = n; Matrix x = Linspace(-4.0, 4.0, m+1, 1); Matrix y = Linspace(-4.0, 4.0, n+1, 1); Matrix f(x.Size(), y.Size()); for(int i = 0; i < x.Size(); i++){ for(int j = 0; j < y.Size(); j++){ f(i, j) = 1/(1+(x(i)*x(i)) + (y(j)*y(j))); } } Matrix a = Linspace(-4.0, 4.0, 201, 1); a.Write("avals.txt"); Matrix b = Linspace(-4.0, 4.0, 101, 1); b.Write("bvals.txt"); Matrix p6(a.Size(), b.Size()); for(int i = 0; i < a.Size(); i++){ for(int j = 0; j < b.Size(); j++){ p6(i, j) = Lagrange2D(x, y, f, a(i), b(j)); } } p6.Write("p6_uni.txt"); n = 24; m = n; x = Linspace(-4.0, 4.0, m+1, 1); y = Linspace(-4.0, 4.0, n+1, 1); f = Matrix(x.Size(), y.Size()); for(int i = 0; i < x.Size(); i++){ for(int j = 0; j < y.Size(); j++){ f(i, j) = 1/(1+(x(i)*x(i)) + (y(j)*y(j))); } } Matrix p24(a.Size(), b.Size()); for(int i = 0; i < a.Size(); i++){ for(int j = 0; j < b.Size(); j++){ p24(i, j) = Lagrange2D(x, y, f, a(i), b(j)); } } p24.Write("p24_uni.txt"); Matrix runge(201, 101); for(int i = 0; i < a.Size(); i++){ for(int j = 0; j < b.Size(); j++){ runge(i, j) = 1/(1+(a(i)*a(i)) + (b(j)*b(j))); } } //create runge matrix runge.Write("Runge.txt"); }
int main(int argc, char * argv[]){ double time_min = 0; double time_max = 10; F f; FD fd; f.solveE(2.0, 1.25); fd.solveE(2.0, 1.25); Matrix t = Linspace(time_min, time_max, 1, 10000); Matrix x(t.Size() ); Matrix y(t.Size() ); double w = 0; double rw = 0; for(int i = 0; i < t.Size() ; i++){ f.setT( t(i) ); fd.setT( t(i) ); w = newton(f,fd, w, 6, 1e-5, false); rw = radialPosition(2.0, 1.25, w); x(i) = rw * cos(w); y(i) = rw * sin(w); } t.Write("t.txt"); x.Write("x.txt"); y.Write("y.txt"); return 0; }
int main(int argc, char** argv){ //Setup tolerances for experiments double rtol, atol; rtol = 1e-11; atol = 1e-15; // Create an array of 400 evenly-spaced T values over the // interval[800,1200] K. Output this to disk as the file // Temp.txt Matrix T_values = Linspace(800, 1200, 400, 1); T_values.Write("Temp.txt"); // Create an array of 600 evenly-spaced t values over the // interval[1 sec,48 hours] K. Output this to disk as the file // temp.txt Matrix t_values = Linspace(1, 172800, 600, 1); t_values.Write("time.txt"); // Create a 400 x 600 array that contains C(0.002,t,T). // Output this to disk as the file C2mm.txt //carbon(0.002, t_values(300), T_values(45), rtol, atol); Matrix C2MM(400, 600); for(int i = 0 ; i < T_values.Size(); i++){ for(int j = 0; j < t_values.Size(); j++){ C2MM(i, j) = carbon( 0.002, t_values(j), T_values(i), rtol, atol); } } C2MM.Write("C2mm.txt"); // Create a 400 x 600 array that contains C(0.004,t,T). // Output this to disk as the file C4mm.txt Matrix C4MM(400, 600); for(int i = 0 ; i < T_values.Size(); i++){ for(int j = 0; j < t_values.Size(); j++){ C4MM(i, j) = carbon( 0.004, t_values(j), T_values(i), rtol, atol); } } C4MM.Write("C4mm.txt"); // Create an array of length 600 containing C(0.002,t,800) // Output to disk as the file C2mm_800K.txt . Repeat this // to output the carbon concentrations for 2mm depth at // 900K (C2mm_900K.txt), 1000K (C2mm_1000K.txt), // 1100K (C2mm_24hour.txt), 1200K (C2mm_1200K.txt) Matrix C2mm_800K(600); Matrix C2mm_900K(600); Matrix C2mm_1000K(600); Matrix C2mm_1100K(600); Matrix C2mm_1200K(600); for(int i =0 ; i < 600 ; i++){ C2mm_800K(i) = carbon(0.002, t_values(i), 800, rtol, atol); C2mm_900K(i) = carbon(0.002, t_values(i), 900, rtol, atol); C2mm_1000K(i) = carbon(0.002, t_values(i), 1000, rtol, atol); C2mm_1100K(i) = carbon(0.002, t_values(i), 1100, rtol, atol); C2mm_1200K(i) = carbon(0.002, t_values(i), 1200, rtol, atol); } C2mm_800K.Write("C2mm_800K.txt"); C2mm_900K.Write("C2mm_900K.txt"); C2mm_1000K.Write("C2mm_1000K.txt"); C2mm_1100K.Write("C2mm_24hour.txt"); C2mm_1200K.Write("C2mm_1200K.txt"); // Create an array of length 600 containing C(0.004,t,800) // Output to disk as the file C4mm_800K.txt . Repeat this // to output the carbon concentrations for 2mm depth at // 900K (C4mm_900K.txt), 1000K (C4mm_1000K.txt), // 1100K (C4mm_1100K.txt), 1200K (C4mm_1200K.txt) Matrix C4mm_800K(600); Matrix C4mm_900K(600); Matrix C4mm_1000K(600); Matrix C4mm_1100K(600); Matrix C4mm_1200K(600); for(int i =0 ; i < 600 ; i++){ C4mm_800K(i) = carbon(0.004, t_values(i), 800, rtol, atol); C4mm_900K(i) = carbon(0.004, t_values(i), 900, rtol, atol); C4mm_1000K(i) = carbon(0.004, t_values(i), 1000, rtol, atol); C4mm_1100K(i) = carbon(0.004, t_values(i), 1100, rtol, atol); C4mm_1200K(i) = carbon(0.004, t_values(i), 1200, rtol, atol); } C4mm_800K.Write("C4mm_800K.txt"); C4mm_900K.Write("C4mm_900K.txt"); C4mm_1000K.Write("C4mm_1000K.txt"); C4mm_1100K.Write("C4mm_1100K.txt"); C4mm_1200K.Write("C4mm_1200K.txt"); return 0; }
int main(int argc, const char * argv[]) { // insert code here... double coeff[13];//array of coefficients for taylor polynomial of cos(x) bool neg=false;//if coefficient is supposed to be negative, then true for (int i=0.0; i<13; i++) {//assigns coefficients to array if(i%2==0) {if(!neg) { coeff[i]=(double)(1.0/factorial(i)); neg=true; } else { coeff[i]=(double)(-1.0/factorial(i)); neg=false; } } else{ coeff[i]=0; } } Matrix z=Linspace(-3, 3, 601);//creates matrix with 601 evenly div numbers between -3 and 3 Matrix p4coeff(1,5,coeff);//matrix with first 4 taylor coefficients Matrix p4(1,601);//matrix with result for 4th degree polynomial evaluated at z for (int i=0;i<601;i++) { p4(i)=nest(p4coeff,z(i)); } p4.Write("p4.txt");//wriete results to text file //same as above for 8th degree polynomial Matrix p8coeff(1,9,coeff); Matrix p8(1,601); for (int i=0;i<601;i++) { p8(i)=nest(p8coeff,z(i)); } p8.Write("p8.txt"); //same as above for 12th degree polynomial Matrix p12coeff(1,13,coeff); Matrix p12(1,601); for (int i=0;i<601;i++) { p12(i)=nest(p12coeff,z(i)); } p12.Write("p12.txt"); // all points are evaluated at cos(x) Matrix f(1,601); for (int i=0;i<601;i++) { f(i)=cos(z(i)); } f.Write("f.txt"); //calculate relative error for the three taylor polynomials Matrix err4(1,601); for (int i=0;i<601;i++) { err4(i)=cos(z(i))-p4(i); } err4.Abs(); err4.Write("err4.txt"); Matrix err8(1,601); for (int i=0;i<601;i++) { err8(i)=cos(z(i))-p8(i); } err8.Abs(); err8.Write("err8.txt"); Matrix err12(1,601); for (int i=0;i<601;i++) { err12(i)=cos(z(i))-p12(i); } err12.Abs(); err12.Write("err12.txt"); z.Write("z.txt"); }
int main(){ Matrix a = Linspace(0.0, 5.0, 5, 1); for(int i = 0; i < a.Size(); i++) std::cout << a(i) << std::endl; }