<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" &lt;<a href="mailto:xxy113@psu.edu">xxy113@psu.edu</a>&gt; 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 = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 &nbsp;y =1.000000e+00 &nbsp;0.000000e+00 &nbsp;0.000000e+00, <br></blockquote><blockquote type="cite">At t = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.01 &nbsp;y =9.996000e-01 &nbsp;4.000000e-04 &nbsp;0.000000e+00, <br></blockquote><blockquote type="cite">At t = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.02 &nbsp;y =9.992002e-01 &nbsp;-4.720016e-02 &nbsp;4.800000e-02, <br></blockquote><blockquote type="cite">At t = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.03 &nbsp;y =7.722397e-01 &nbsp;-6.681768e+02 &nbsp;6.684045e+02, <br></blockquote><blockquote type="cite">At t = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.04 &nbsp;y =-4.466124e+07 &nbsp;-1.338934e+11 &nbsp;1.339381e+11, <br></blockquote><blockquote type="cite">At t = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.05 &nbsp;y =-1.793342e+24 &nbsp;-5.376439e+27 &nbsp;5.378233e+27, <br></blockquote><blockquote type="cite">At t = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.06 &nbsp;y =-2.891574e+57 &nbsp;-8.668938e+60 &nbsp;8.671830e+60, <br></blockquote><blockquote type="cite">At t = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.07 &nbsp;y =-7.517556e+123 &nbsp;-2.253763e+127 &nbsp;2.254515e+127, <br></blockquote><blockquote type="cite">At t = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.08 &nbsp;y =-5.081142e+256 &nbsp;-1.523326e+260 &nbsp;1.523834e+260, <br></blockquote><blockquote type="cite">At t = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0.09 &nbsp;y =-inf &nbsp;nan &nbsp;inf, <br></blockquote><br>There is a reason people don't use forward Euler for stiff systems. &nbsp;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> &nbsp;&nbsp;Mat jac=*J;<br> &nbsp;&nbsp;PetscScalar v[3],*x;<br>- &nbsp;PetscInt row,col;<br>+ &nbsp;PetscInt row[3] = {0,1,2},col;<br> &nbsp;&nbsp;PetscErrorCode ierr;<br> &nbsp;&nbsp;ierr = VecGetArray(X,&amp;x);CHKERRQ(ierr);<br> &nbsp;&nbsp;v[0]=-0.04;<br> &nbsp;&nbsp;v[1]=0.04;<br> &nbsp;&nbsp;v[2]=0.0;<br>- &nbsp;row=0;<br> &nbsp;&nbsp;col=0;<br>- &nbsp;ierr = MatSetValues(jac,3,&amp;row,1,&amp;col,v,INSERT_VALUES);CHKERRQ(ierr);<br>+ &nbsp;ierr = MatSetValues(jac,3,row,1,&amp;col,v,INSERT_VALUES);CHKERRQ(ierr);<br> &nbsp;&nbsp;v[0]=1.0e4*x[2];<br> &nbsp;&nbsp;v[1]=-1.0e4*x[2]-6.0e7*x[1];<br> &nbsp;&nbsp;v[2]=6.0e7*x[1];<br> &nbsp;&nbsp;col=1;<br>- &nbsp;ierr = MatSetValues(jac,3,&amp;row,1,&amp;col,v,INSERT_VALUES);CHKERRQ(ierr);<br>+ &nbsp;ierr = MatSetValues(jac,3,row,1,&amp;col,v,INSERT_VALUES);CHKERRQ(ierr);<br> &nbsp;&nbsp;v[0]=1.0e4*x[1];<br> &nbsp;&nbsp;v[1]=-1.0e4*x[1];<br> &nbsp;&nbsp;v[2]=0.0;<br> &nbsp;&nbsp;col=2;<br>- &nbsp;ierr = MatSetValues(jac,3,&amp;row,1,&amp;col,v,INSERT_VALUES);CHKERRQ(ierr);<br>+ &nbsp;ierr = MatSetValues(jac,3,row,1,&amp;col,v,INSERT_VALUES);CHKERRQ(ierr);<br> &nbsp;&nbsp;ierr = MatAssemblyBegin(jac,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br> &nbsp;&nbsp;ierr = VecRestoreArray(X,&amp;x);CHKERRQ(ierr);<br> &nbsp;&nbsp;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>