Message Boards Message Boards

0
|
2432 Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

What does (/. % /.) mean ?

Posted 2 years ago

Example =>

Plot[Evaluate[x[t] /. % /. {{c -> 0.3}, {c -> 0.2}, {c -> 0.4}}], {t, 0, 5}, AxesLabel -> {t, "x(t)"}]

What does (/. % /.) mean ? I don't understand and I can't search it . here is the full example : enter image description here

POSTED BY: Aya Zanaty
5 Replies

Aya,

/. Is an in-line a Shortcut for ReplaceAll[]

% refers to the previous output

So your line replaces the solution from DSolve in for x and then replaces some individual parameters before plotting.

Regards,

Neil

POSTED BY: Neil Singer
Posted 2 years ago

Hi Aya,

Take a look at this post on MSE for a summary of many WL operators. The entire thread has a lot of useful information for beginners.

POSTED BY: Rohit Namjoshi

Aya,

As a recommendation, I really dislike using % anywhere in code. It makes the code less readable and less predictable. It's more useful for interactive use in Mathematica. If you evaluate parts of your notebook out of order, it will break.

I would have written that code by setting the solution to a variable and then define a list of cases to plot:

solution = DSolve[...]
plotcases = {{c->0.3},...}
Plot[Evaluate[x[t] /. solution /. plotcases], {t, 0, 5}, AxesLabel -> {t, "x(t)"}]

So you can see that you are plotting the x given by the solution for each of the plotcases. Now it does not matter if you go back and make a change and reevaluate anything out of order.

Regards,

POSTED BY: Neil Singer
Posted 2 years ago

Thanks a lot!

POSTED BY: Aya Zanaty
Posted 2 years ago

Thank you so much, mister Neil! You were so helpful twice, so thank you so much again!

POSTED BY: Aya Zanaty
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