zanmat2
(Mark Turtsinskyi)
March 21, 2014, 5:04pm
1
Good evening everybody!
Unfortunately, I didn’t manage to draw the graph of the difference of two interpolating functions, that were received as numerical solution of two ODEs.
Some typical methods, such as ordinary “-” and some combinations with these functions didn’t help.
Thanks beforehand.
r := 0.1;
c := 1/r;
c1 := 0.01;
a := 1; b := 0;
s = NDSolve[{Z''[z] + r*(-c1*Sin[z]*Exp[-z/r] + c)*Z[z] == 0,
Z[b] == 0, Z'[0] == a}, Z[z], {z, 0, 100}];
s1 = NDSolve[{Y''[z] + r*c*Y[z] == 0, Y[b] == 0, Y'[0] == a},
Y[z], {z, 0, 100}];
nsol[z_]: = (Z[z] /. (s[[1]][[1]])) - (Y[z] /. (s1[[1]][[1]]));
Plot[nsol[z], {z, 0, 100}]
r := 0.1;
c := 1/r;
c1 := 0.01;
a := 1; b := 0;
s = NDSolve[{Z''[z] + r*(-c1*Sin[z]*Exp[-z/r] + c)*Z[z] == 0, Z[b] == 0, Z'[0] == a}, Z[z], {z, 0, 100}][[1, 1]];
s1 = NDSolve[{Y''[z] + r*c*Y[z] == 0, Y[b] == 0, Y'[0] == a}, Y[z], {z, 0, 100}][[1, 1]];
nsol = (Z[z] - Y[z]) /. {s, s1};
Plot[nsol, {z, 0, 100}]
memsa
(Mark Dooris)
March 22, 2014, 3:35am
4
Just another way (with no advantage) you can solve the system for the desired function:
r := 0.1;
c := 1/r;
c1 := 0.01;
a := 1; b := 0;
sol = Y[z] - Z[z] /.First@NDSolve[
{{
Z''[z] + r*(-c1*Sin[z]*Exp[-z/r] + c)*Z[z] == 0,
Z[b] == 0, Z'[0] == a}, {Y''[z] + r*c*Y[z] == 0, Y[b] == 0,
Y'[0] == a
}},
{Y[z] - Z[z]}, {z, 0, 100}];
You can plot:
Plot[sol, {z, 0, 100}]