I have a function,I want to plot it
This piecewise function looks very complicated, because the boundary changes as c changes. want to just Plot it, not Manipulate
To solve this problem, I first do it manually, one by one.Here c takes on three special values,like this
Then use the Show function to integrate them
This is very complicated and requires constant manual operation,Therefore, I improved my approach by discretizing C, defining functions of each interval separately, and finally integrating them with piecewise functions
(*=== 常数 ===*)
Clear["Global`*"]
rf = 0;
theta = 0.1;
p = 1;
(*=== 边界 ===*)
boundary1 = 0;
boundary2 = c;
boundary3 =
c*(2 - c (1 + rf)/(1 - theta)*p + (1 - theta)*p/(1 + rf) - c) +
1/2 ((1 - theta)*p/(1 + rf) - c)^2;
boundary4 = 2;
(*=== 分段函数定义 ===*)
funb1[b_] := 0;
funb2[b_] := -c - (2^(1/3)*(-6 b + 12 c -
3 c^2))/(3 *(54 c^2 +
Sqrt[2916 c^4 + 4 (-6 b + 12 c - 3 c^2)^3])^(1/
3)) + (54 c^2 +
Sqrt[2916 c^4 + 4*(-6 b + 12 c - 3 c^2)^3])^(1/3)/(3*2^(1/3));
funb3[b_] := (1 - theta)*p/(1 + rf) - c;
fun = Table[(Through[{funb1, funb2, funb3}@{x}] // Flatten), {c, 0.3,
0.8, 0.01}];
boundary =
Table[{boundary1, boundary2, boundary3, boundary4}, {c, 0.3, 0.8,
0.01}];
I'm discretizing C, so I'm using these two lines of code
fun = Table[(Through[{funb1, funb2, funb3}@{x}] // Flatten), {c, 0.3,
0.8, 0.01}];
boundary =
Table[{boundary1, boundary2, boundary3, boundary4}, {c, 0.3, 0.8,
0.01}];
After I discretize C, then I want to define the piecewise function that I want once and for all, but I don't know how to do it, and defining the piecewise function manually would be very, very tedious.
Please help me. Thank you
Piecewise
see here? $\endgroup$f[c_,x_] := Piecewise[{{0,0<=x<=c},{x-c,c<=x<=2*c},{c,2*c<=x<=2}}]
. Suppose we then setp[c_] := Plot[f[c,x],{x,0,2}]
. Thenp[0.2]
andp[0.7]
will give you two plots. Does this help? $\endgroup$