void secant_method(int argc, char *argv[]) { //Secant method is x_n = x_n-1 - f(x_n-1)* ((x_n-1 - x_n-2) / (f(x_n-1) - f(x_n-2))) //From quiz 3, x1 = 2.1; x0 = 2.2 where x_n-1 = x1 and x_n-2 = x0 //From quiz 3, another problem, x0 = 1.0 and x1 = 1.1 float x1 = 1.0; float x0 = 1.1; float result = x1 - fnx(x1) * ( (x1 - x0) / (fnx(x1) - fnx(x0))); printf("The result is: %f\n", result); }
int main() { char string1[50]; char string2[50]; int var; printf("Enter a string:"); fgets(string1, 50, stdin); printf("Enter a string:"); fgets(string2, 50, stdin); char *word1 = string1; char *word2 = string2; var = fnx(word1, word2); printf("%d\n",var); return 0; }
void fx() { fnx((int *)0); fnx((void *)0); // { dg-message "instantiated from here" } }
void fx() { fnx((int *)0); fnx((void *)0); }
//--------------------------------------------------------- void EulerShock2D::precalc_limiter_data() //--------------------------------------------------------- { //--------------------------------------------- // pre-calculate element geometry and constant // factors for use in this->EulerLimiter2D() //--------------------------------------------- Lim_AVE = 0.5 * MassMatrix.col_sums(); DMat dropAVE = eye(Np) - outer(ones(Np),Lim_AVE); Lim_dx = dropAVE*x; Lim_dy = dropAVE*y; // Extract coordinates of vertices of elements IVec v1=EToV(All,1); Lim_xv1=VX(v1); Lim_yv1=VY(v1); IVec v2=EToV(All,2); Lim_xv2=VX(v2); Lim_yv2=VY(v2); IVec v3=EToV(All,3); Lim_xv3=VX(v3); Lim_yv3=VY(v3); const DVec &xv1=Lim_xv1,&xv2=Lim_xv2,&xv3=Lim_xv3; const DVec &yv1=Lim_yv1,&yv2=Lim_yv2,&yv3=Lim_yv3; DMat &fnx=Lim_fnx, &fny=Lim_fny, &fL=Lim_fL; // Compute face unit normals and lengths fnx.resize(3,K); fny.resize(3,K); // fnx = (3,K) = [yv2-yv1; yv3-yv2; yv1-yv3]; fnx.set_row(1, yv2-yv1); fnx.set_row(2, yv3-yv2); fnx.set_row(3, yv1-yv3); // fny = (3,K) = -[xv2-xv1;xv3-xv2;xv1-xv3]; //fny.set_row(1, xv2-xv1); fny.set_row(2, xv3-xv2); fny.set_row(3, xv1-xv3); fny.set_row(1, xv1-xv2); fny.set_row(2, xv2-xv3); fny.set_row(3, xv3-xv1); fL = sqrt(sqr(fnx)+sqr(fny)); fnx.div_element(fL); fny.div_element(fL); //------------------------------------------------------- // Compute coords of element centers and face weights //------------------------------------------------------- // Find neighbors in patch Lim_E1=EToE(All,1); Lim_E2=EToE(All,2); Lim_E3=EToE(All,3); // Compute coordinates of element centers xc0=Lim_AVE*x; xc1=xc0(Lim_E1); xc2=xc0(Lim_E2); xc3=xc0(Lim_E3); yc0=Lim_AVE*y; yc1=yc0(Lim_E1); yc2=yc0(Lim_E2); yc3=yc0(Lim_E3); // Compute weights for face gradients A0=Lim_AVE*J*TWOTHIRD; A1=A0+A0(Lim_E1); A2=A0+A0(Lim_E2); A3=A0+A0(Lim_E3); A1_A2_A3 = A1+A2+A3; // Find boundary faces for each face Lim_id1=find(BCType.get_col(1),'!',0); Lim_id2=find(BCType.get_col(2),'!',0); Lim_id3=find(BCType.get_col(3),'!',0); // Compute location of centers of reflected ghost elements at boundary faces if (1) { DMat FL1=fL(1,Lim_id1), Fnx1=fnx(1,Lim_id1), Fny1=fny(1,Lim_id1); DVec fL1=FL1, fnx1=Fnx1, fny1=Fny1; DVec H1 = 2.0*(dd(A0(Lim_id1),fL1)); xc1(Lim_id1) += 2.0*fnx1.dm(H1); yc1(Lim_id1) += 2.0*fny1.dm(H1); DMat FL2=fL(2,Lim_id2), Fnx2=fnx(2,Lim_id2), Fny2=fny(2,Lim_id2); DVec fL2=FL2, fnx2=Fnx2, fny2=Fny2; DVec H2 = 2.0*(dd(A0(Lim_id2),fL2)); xc2(Lim_id2) += 2.0*fnx2.dm(H2); yc2(Lim_id2) += 2.0*fny2.dm(H2); DMat FL3=fL(3,Lim_id3), Fnx3=fnx(3,Lim_id3), Fny3=fny(3,Lim_id3); DVec fL3=FL3, fnx3=Fnx3, fny3=Fny3; DVec H3 = 2.0*(dd(A0(Lim_id3),fL3)); xc3(Lim_id3) += 2.0*fnx3.dm(H3); yc3(Lim_id3) += 2.0*fny3.dm(H3); } // Find boundary faces IVec bct = trans(BCType); Lim_idI = find(bct, '=', (int)BC_In); Lim_idO = find(bct, '=', (int)BC_Out); Lim_idW = find(bct, '=', (int)BC_Wall); Lim_idC = find(bct, '=', (int)BC_Cyl); Lim_ctx.resize(3,K); Lim_cty.resize(3,K); Lim_ctx.set_row(1,xc1); Lim_ctx.set_row(2,xc2); Lim_ctx.set_row(3,xc3); Lim_cty.set_row(1,yc1); Lim_cty.set_row(2,yc2); Lim_cty.set_row(3,yc3); // load the set of ids Lim_ids.resize(6); Lim_ids(1)=1; Lim_ids(2)=Nfp; Lim_ids(3)=Nfp+1; Lim_ids(4)=2*Nfp; Lim_ids(5)=3*Nfp; Lim_ids(6)=2*Nfp+1; limQ = Q; }