2

I have two functions h2 and v2 that I need to graph using Piecewise and be able to manipulate certain variables in the equations. Whatever I try, my code returns a blank plot.

Manipulate[
Plot[
Piecewise[
{{{h2[t], t0 < t}, 0},
{{v2[t], 0 < t < t0}, 0}}],
{t, 0, 500}],
{{t, 0, Time}, 0, 500},
{{A, 200, Alpha}, 0, 500},
{{B, 1, Bravo}, 0, 50},
{{C, 0.5, Charlie}, 0, 50},
{{D, 0.1, Delta}, 0, 1}]

I know that both of my functions h2 and v2 are correct.

As you can see, v2 starts at t=0 and ends at t=t0, and h2 starts at t=t0.

I tried removing the t Manipulator to no avail.

Here are equations v2 and h2:

v2[t] = -((C g)/D) - g (-(C/D) + t) + A Log[(D + B)/B]

h2[t] = (A C)/D - (C^2 g)/(2 D^2) - (g t^2)/2 - 
(A B Log[(C + B)/B])/D + A t Log[(C + B)/B]
Karsten7
  • 27,448
  • 5
  • 73
  • 134
chris493
  • 21
  • 2
  • 2
    You have a t as the independent variable inside the Plot command and a t as a Manipulated variable. There might be some conflict there. Otherwise, without the definitions of h2[t] and v2[t], it's hard to know what's going wrong. Have you tried coming up with a simpler version first that doesn't have so many moving parts (i.e. so many parameters) so that you can narrow in on what might be the issue? That's good trouble-shooting practice. – march Oct 29 '15 at 05:39
  • You still have a problem with t and t0. I'm guessing that {{t, 0, Time}, 0, 500} should be {{t0, 0, Time}, 0, 500}? – march Oct 29 '15 at 06:17
  • There are other problems. Don't use capital letters for user-defined symbols in Mathematica, because all built-in functions are capitalized. For instance, both C and D are reserved symbols in Mathematica. Perhaps first try to just plot the function with a set of parameters first; once you get that working, then try the Manipulate. Also, g is undefined! Is it a number or did you mean to put it in as a Manipulated variable? Also, your syntax for Piecewise is wrong. Also, your definitions for v2 and h2 should look like h2[t_] and v2[t_]. – march Oct 29 '15 at 06:21
  • Basically, you need to spend some time with the very helpful Mathematica documentation to figure out correct Mathematica syntax, and you need to spend some time doing the simple things first, and then building up more complicated code once you have the simpler code working. – march Oct 29 '15 at 06:25
  • I've narrowed it down to my piecewise function being incorrect. Any help on that? I've read the documentation but didn't make much sense of it. – chris493 Oct 29 '15 at 06:42
  • Piecewise[{{h2[t], t0 < t}, {v2[t], 0 < t < t0}}]? – march Oct 29 '15 at 06:49
  • Okay I've got the plotting all sorted however now Mathematica is calculating an equation incorrectly.

    I've input values of A,B,C,D,g and the correct value for t0. My calculator gives me the correct value substituting the variables into the mathematica piecewise equation, however mathematica is way off.

    – chris493 Oct 29 '15 at 13:37
  • @chris493 then please update your question accordingly. Just to be sure: you are aware that Log is the natural (Euler's) logarithm, correct? Many other systems have this as the base-10 logarithm. Additionally C and D are system symbols and should not be used for your own variables. – Oleksandr R. Oct 29 '15 at 13:40
  • I've changed the C and D variables in my code however there's no difference. I'll look into the natural log. – chris493 Oct 29 '15 at 13:45

0 Answers0