Question: conditional if

Hello everyone,

I need your helps .I have this code to solve equation numerically with random coefficients, but sometimes the solution find a singularity, for that I create conditional if to avoid it , but its does not work.

Thank you a lot.




eq := a*(diff(x(t), `$`(t, 2)))+b*(diff(x(t), `$`(t, 1)))+sin(x(t))*(diff(x(t), `$`(t, 1)))+2/x(t);


cis := x(0) = .25, (D(x))(0) = 0;


Simpson := proc (f, a, b, n) local h, S1, S2, S, i; h := evalf(((1/2)*b-(1/2)*a)/n); S1 := 0.; for i from 0 to n-1 do S1 := S1+f(a+(2*i+1)*h) end do; S2 := 0.; for i to n-1 do S2 := S2+f(a+2*i*h) end do; S := (1/3)*h*(f(a)+f(b)+4*S1+2*S2); return S end proc:






Q1 := []; for jj to 10 do simplfloat := rand(-1.0 .. 1.0); h := simplfloat(); a := abs(amin+(amax-amin)*h); b := abs(bmin+(bmax-bmin)*h); solut := dsolve([eq, cis], numeric, maxfun = 0, output = procedurelist); sd := proc (i) options operator, arrow; abs(rhs(solut(i)[2])*rhs(solut(i)[2])) end proc; eng := Simpson(sd, 5, 6, 10); if 'FAIL' then return  else  end if; Q1 := [op(Q1), [jj, a, b, h, eng]]; writedata("test.dat", Q1) end do

Error, (in solut) cannot evaluate the solution further right of .22544264, probably a singularity




Please Wait...