Hello everyone, previously I had ask about NDSolve with specified Runge Kutta 4th Order method for my equation. And here is what I got for combining few equations into one.
Z = 1
In[199]:= Clear[Z]
In[197]:=
ClassicalRungeKuttaCoefficients[4, prec_] :=
With[{amat = {{1/2}, {0, 1/2}, {0, 0, 1}},
bvec = {1/6, 1/3, 1/3, 1/6}, cvec = {1/2, 1/2, 1}},
N[{amat, bvec, cvec}, prec]]
In[208]:= NDSolve[{Derivative[1][y][x] ==
Piecewise[{{(y[x] + x^3 + 3 Z),
0 <= x <= 1},
{(y[x] + x^2 + 2 Z),
1 <= x <= 2},
{(y[x] + x + Z),
2 <= x <= 3}}]
, y[0] == 0}, y, {x, 0, 3},
Method -> {"ExplicitRungeKutta", "DifferenceOrder" -> 4,
"Coefficients" -> ClassicalRungeKuttaCoefficients},
"StartingStepSize" -> 1/10]
Out[208]= {{y -> InterpolatingFunction[{{0., 3.}}, <>]}}
Z is a variable that I can change depending of the value for y[3] that I need.
Here’s the questions;
-
What command that I need to key-in in order for the equations to automatically generate the Plot and the value for y[3]?
As what I have been currently doing is I keep on clicking “get solution”, “plot” and " evaluate at point" buttons provided by Mathematica itself. -
I need to use Loop command to find the value of Z so that I can get the value of y[3]=100 exactly. Currently I’m just try the value of Z randomly until I obtain y[3]=100 exactly. The For loop value of Z increment is 0.01 manually, the tutorials given to me was i++ command but the increment value is 1, how do I change it?
Thank you for your help guys.