Message Boards Message Boards

Plot a differential equation result?

Posted 8 years ago

I am solving this simple differential equation and for this result for it

{{x[t] -> 1.1994*10^7 r^2 t - 118134. E^(-((8.46493*10^-6 t)/r^2)) r^2 C[1] + C[2] + 17.223 r t Cos[theta]}}

I then assumed C[1] and C[2] to be 1 and put in x as a function of the variables: t, r and theta

x[t_, r_, theta_] := x[t] -> 1.1993963068181815`*^7 r^2 t - 118134.46969696967` E^(-((8.464929859719441`*^-6 t)/r^2)) r^2 1 + 1 + 17.22301136363636` r t Cos[theta]

When I try to plot using:

Plot[x[t, 0.5, 2Pi], {t, 0, 0.5}, PlotRange -> {{0, 0.5}, All}]

I get an empty graph eventhough it was working earlier and plotted the graph fine. Any idea why this happens?

POSTED BY: Reem Refaie
6 Replies
Posted 8 years ago

Now it finally worked when I used the underscores, perfect! Thanks for the help

POSTED BY: Reem Refaie
Posted 8 years ago

I tried to change some of the notes above but it is still not working, maybe if I write it in code you can see it better and see the problem easier.

Dsolve [Pi r^2 [Rho] x''[t] + 8 Pi [Eta] x'[t] == p Pi r^2 + 2 Pi r [Gamma] Cos[theta], x[t], t]

which gave me this solution after I defined some of the variables:

x[t_, r_, theta_] := 1.1993963068181815`*^7 r^2 t - 118134.46969696967` E^(-((8.464929859719441`*^-6 t)/r^2)) r^2 1 + 1 + 17.22301136363636` r t Cos[theta]

And this is what I entered for plotting:

Plot[x[t, 0.5, 2 Pi], {t, 0, 0.5}, PlotRange -> All]

Hope this is easier to read :)

POSTED BY: Reem Refaie

Oh, okay. Well, then the fix is simply my first suggestion; just get rid of the rule and add the underscores.

POSTED BY: Bianca Eifert
Posted 8 years ago

Sorry that was a typing error in my question I edited it.

POSTED BY: Reem Refaie

Hi Reem, can you please format your examples as code in future posts? Makes it easier to copy things.

Let's look at your problem though. First of all, there are three variables: t, r, and theta. You can define your result as a function of all three like this:

x[t_, r_, theta_] := 
  1.1993963068181815*^7 r^2 t - 
   118134.46969696967 E^(-((8.464929859719441*^-6 t)/r^2)) r^2 1 + 
   1 + 17.22301136363636 r t Cos[theta];

Things to note: Use underscores for each function argument, you want to use all arguments as patterns. On the right hand side of your definition, the rule x[t]->... certainly doesn't do what you expect. And lastly, defining the same function with different numbers of arguments (like x[t] and x[t,r,theta]) is possible, but it's not something you should try unless you're sure you understand "simple" functions that have only one definition.

Alright, so now that you have a definition for x[t,r,theta], you can pick a fixed value for t and theta and plot x as a function of t, like this:

Plot[x[t, .01, 3], {t, 0, 10}]

Or, if you already know the fixed values you'll want to use, you can also do this (and it might make more sense depending on the context):

x[t_] := 1.1993963068181815*^7 r^2 t - 
    118134.46969696967 E^(-((8.464929859719441*^-6 t)/r^2)) r^2 1 + 
    1 + 17.22301136363636 r t Cos[theta] /. {r -> .01, theta -> 3};
Plot[x[t], {t, 0, 10}]

But you can't make a plot of something that still contains symbolic expressions. You can also make a Plot3D with two variables, if that makes more sense for your problem.

POSTED BY: Bianca Eifert

There are several problems. You are defining a function with a rule, you don't have underscores after t and r and you are not giving values for them in your Plot function.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract