<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I got the correct results! Thanks!<div><br></div><div>Could you please tell me whether I can use TS to solve ODE without providing Jacobian matrix?</div><div><br><div><div>On Jun 22, 2010, at 7:19 PM, Jed Brown wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Tue, 22 Jun 2010 19:09:32 -0400, "XUAN YU" <<a href="mailto:xxy113@psu.edu">xxy113@psu.edu</a>> wrote:<br><blockquote type="cite">I got my program to run. But the results doesn't make any sence.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">At t = 0 y =1.000000e+00 0.000000e+00 0.000000e+00, <br></blockquote><blockquote type="cite">At t = 0.01 y =9.996000e-01 4.000000e-04 0.000000e+00, <br></blockquote><blockquote type="cite">At t = 0.02 y =9.992002e-01 -4.720016e-02 4.800000e-02, <br></blockquote><blockquote type="cite">At t = 0.03 y =7.722397e-01 -6.681768e+02 6.684045e+02, <br></blockquote><blockquote type="cite">At t = 0.04 y =-4.466124e+07 -1.338934e+11 1.339381e+11, <br></blockquote><blockquote type="cite">At t = 0.05 y =-1.793342e+24 -5.376439e+27 5.378233e+27, <br></blockquote><blockquote type="cite">At t = 0.06 y =-2.891574e+57 -8.668938e+60 8.671830e+60, <br></blockquote><blockquote type="cite">At t = 0.07 y =-7.517556e+123 -2.253763e+127 2.254515e+127, <br></blockquote><blockquote type="cite">At t = 0.08 y =-5.081142e+256 -1.523326e+260 1.523834e+260, <br></blockquote><blockquote type="cite">At t = 0.09 y =-inf nan inf, <br></blockquote><br>There is a reason people don't use forward Euler for stiff systems. Run<br>with -ts_type beuler or -ts_type theta, after applying the following<br>patch (which fixes your assembly bug).<br><br>Jed<br><br>diff --git a/ex1.c b/ex1.c<br>index ed78cd7..e4bc7f2 100644<br>--- a/ex1.c<br>+++ b/ex1.c<br>@@ -88,25 +88,24 @@ PetscErrorCode FormJacobian(TS ts,PetscReal t,Vec X,Mat *J,Mat *B,MatStructure<br> {<br> Mat jac=*J;<br> PetscScalar v[3],*x;<br>- PetscInt row,col;<br>+ PetscInt row[3] = {0,1,2},col;<br> PetscErrorCode ierr;<br> ierr = VecGetArray(X,&x);CHKERRQ(ierr);<br> v[0]=-0.04;<br> v[1]=0.04;<br> v[2]=0.0;<br>- row=0;<br> col=0;<br>- ierr = MatSetValues(jac,3,&row,1,&col,v,INSERT_VALUES);CHKERRQ(ierr);<br>+ ierr = MatSetValues(jac,3,row,1,&col,v,INSERT_VALUES);CHKERRQ(ierr);<br> v[0]=1.0e4*x[2];<br> v[1]=-1.0e4*x[2]-6.0e7*x[1];<br> v[2]=6.0e7*x[1];<br> col=1;<br>- ierr = MatSetValues(jac,3,&row,1,&col,v,INSERT_VALUES);CHKERRQ(ierr);<br>+ ierr = MatSetValues(jac,3,row,1,&col,v,INSERT_VALUES);CHKERRQ(ierr);<br> v[0]=1.0e4*x[1];<br> v[1]=-1.0e4*x[1];<br> v[2]=0.0;<br> col=2;<br>- ierr = MatSetValues(jac,3,&row,1,&col,v,INSERT_VALUES);CHKERRQ(ierr);<br>+ ierr = MatSetValues(jac,3,row,1,&col,v,INSERT_VALUES);CHKERRQ(ierr);<br> ierr = MatAssemblyBegin(jac,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br> ierr = VecRestoreArray(X,&x);CHKERRQ(ierr);<br> ierr = MatAssemblyEnd(jac,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br><br></div></blockquote></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Xuan YU (<span class="Apple-style-span" style="font-family: arial; font-size: 16px; white-space: pre; ">俞烜<span class="Apple-style-span" style="font-family: Helvetica; font-size: medium; white-space: normal; ">)</span></span></div><div><a href="mailto:xxy113@psu.edu">xxy113@psu.edu</a></div><div><br></div></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"> </div><br></div></body></html>