ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 21 Sep 2019 16:50:51 +0200How to plot multiple tangent lines on a graphhttps://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/ I installed Sage today, so I am unfamiliar with the software. I have an equation f(x)=sqrt(625-x^2), and f'(x)=-x/sqrt(625-x^2). I am trying to plot both f(x) and f'(x) at 20, 24, -7 and -15 on one graph. To begin I tried:
plot(sqrt(625-x^2) + plot(-x/sqrt(625-^2))
This produced:
![alt text](/ThisPC/C:/Users/owner/Pictures/first plot.png "first plot")
Please let me know if the image doesn't appear as this is my first question. Essentially it is a straight line at the intercepts of 25 and 0 on the y axis. How would I create a simple graph that demonstrates f(x) and f'(x) tangent lines at x = 20, 24, -7 and -15? Many thanks.Fri, 20 Sep 2019 21:57:24 +0200https://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/Comment by Emmanuel Charpentier for <p>I installed Sage today, so I am unfamiliar with the software. I have an equation f(x)=sqrt(625-x^2), and f'(x)=-x/sqrt(625-x^2). I am trying to plot both f(x) and f'(x) at 20, 24, -7 and -15 on one graph. To begin I tried: </p>
<p>plot(sqrt(625-x^2) + plot(-x/sqrt(625-^2))</p>
<p>This produced:</p>
<p><img alt="alt text" src="/ThisPC/C:/Users/owner/Pictures/first plot.png" title="first plot"></p>
<p>Please let me know if the image doesn't appear as this is my first question. Essentially it is a straight line at the intercepts of 25 and 0 on the y axis. How would I create a simple graph that demonstrates f(x) and f'(x) tangent lines at x = 20, 24, -7 and -15? Many thanks.</p>
https://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/?comment=48000#post-id-48000Homework ?Sat, 21 Sep 2019 00:29:13 +0200https://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/?comment=48000#post-id-48000Comment by Open_Sauce for <p>I installed Sage today, so I am unfamiliar with the software. I have an equation f(x)=sqrt(625-x^2), and f'(x)=-x/sqrt(625-x^2). I am trying to plot both f(x) and f'(x) at 20, 24, -7 and -15 on one graph. To begin I tried: </p>
<p>plot(sqrt(625-x^2) + plot(-x/sqrt(625-^2))</p>
<p>This produced:</p>
<p><img alt="alt text" src="/ThisPC/C:/Users/owner/Pictures/first plot.png" title="first plot"></p>
<p>Please let me know if the image doesn't appear as this is my first question. Essentially it is a straight line at the intercepts of 25 and 0 on the y axis. How would I create a simple graph that demonstrates f(x) and f'(x) tangent lines at x = 20, 24, -7 and -15? Many thanks.</p>
https://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/?comment=48008#post-id-48008I am a Quantitative Epidemiology PhD student brushing up on my calculus skills using a free textbook online called Multivariate analysis.Sat, 21 Sep 2019 14:38:38 +0200https://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/?comment=48008#post-id-48008Answer by Emmanuel Charpentier for <p>I installed Sage today, so I am unfamiliar with the software. I have an equation f(x)=sqrt(625-x^2), and f'(x)=-x/sqrt(625-x^2). I am trying to plot both f(x) and f'(x) at 20, 24, -7 and -15 on one graph. To begin I tried: </p>
<p>plot(sqrt(625-x^2) + plot(-x/sqrt(625-^2))</p>
<p>This produced:</p>
<p><img alt="alt text" src="/ThisPC/C:/Users/owner/Pictures/first plot.png" title="first plot"></p>
<p>Please let me know if the image doesn't appear as this is my first question. Essentially it is a straight line at the intercepts of 25 and 0 on the y axis. How would I create a simple graph that demonstrates f(x) and f'(x) tangent lines at x = 20, 24, -7 and -15? Many thanks.</p>
https://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/?answer=48011#post-id-48011> I am a Quantitative Epidemiology PhD student brushing up on my calculus skills using a free textbook online called Multivariate analysis.
Okay, a real call for help. We tend to avoid giving pre-cooked answers to lazy undergrads' homework...
f(x)=sqrt(625-x^2)
Curves=plot([f, f.diff(x)],(-25, 25), ymin=-6, ymax=26, aspect_ratio=1)
Tangents=plot([(f(u)+(x-u)*f.diff(x)(u)) for u in [-15, -7, 20, 24]], (x, -25, 25))
Curves+Tangents
![image description](/upfiles/15690766759226123.png)
This code takes advantage of a couple not-so-obvious \`Sage\` features:
- `plot accepts a *sequence* (here, lists) as first argument.
- In the first call (to get `Curves`), this is a list of (symbolic)
*functions*; the second argument is just a range for the argument of
the function(s).
- In the second case, it is a list of *symbolic expressions*;
Therefore, the second argument specifies the name of the (symbolic)
variable taking values in the range it specifies.
- I didn't bother to fix the colors, the labels nor a legend; this is
left as an (useful) exercise for the reader.
- I *did* specify a range for the ordinates in the first plot. It is
also used for the superposition of the two plots.
A lot more could be said. But:
r.library("fortunes")
r.fortune("'TFM'")
This is all documented in TFM. Those who WTFM don't want to have to WTFM again
on the mailing list. RTFM.
-- Barry Rowlingson
R-help (October 2003)
But you're in luck. TFM is marvelously supplemented by this [book](http://sagebook.gforge.inria.fr/english.html), freely available, which will certainly help you (even if some details (notebook) have changed and others (Python 3) will change soon).
If you're not primarily a native English speaker, the original French version, or a German translation are also available via the same page.Sat, 21 Sep 2019 16:34:03 +0200https://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/?answer=48011#post-id-48011Comment by Emmanuel Charpentier for <blockquote>
<p>I am a Quantitative Epidemiology PhD student brushing up on my calculus skills using a free textbook online called Multivariate analysis.</p>
</blockquote>
<p>Okay, a real call for help. We tend to avoid giving pre-cooked answers to lazy undergrads' homework...</p>
<pre><code>f(x)=sqrt(625-x^2)
Curves=plot([f, f.diff(x)],(-25, 25), ymin=-6, ymax=26, aspect_ratio=1)
Tangents=plot([(f(u)+(x-u)*f.diff(x)(u)) for u in [-15, -7, 20, 24]], (x, -25, 25))
Curves+Tangents
</code></pre>
<p><img alt="image description" src="/upfiles/15690766759226123.png"></p>
<p>This code takes advantage of a couple not-so-obvious `Sage` features:</p>
<ul>
<li>`plot accepts a <em>sequence</em> (here, lists) as first argument.</li>
<li>In the first call (to get <code>Curves</code>), this is a list of (symbolic)
<em>functions</em>; the second argument is just a range for the argument of
the function(s).</li>
<li>In the second case, it is a list of <em>symbolic expressions</em>;
Therefore, the second argument specifies the name of the (symbolic)
variable taking values in the range it specifies.</li>
<li>I didn't bother to fix the colors, the labels nor a legend; this is
left as an (useful) exercise for the reader.</li>
<li>I <em>did</em> specify a range for the ordinates in the first plot. It is
also used for the superposition of the two plots.</li>
</ul>
<p>A lot more could be said. But:</p>
<pre><code>r.library("fortunes")
r.fortune("'TFM'")
This is all documented in TFM. Those who WTFM don't want to have to WTFM again
on the mailing list. RTFM.
-- Barry Rowlingson
R-help (October 2003)
</code></pre>
<p>But you're in luck. TFM is marvelously supplemented by this <a href="http://sagebook.gforge.inria.fr/english.html">book</a>, freely available, which will certainly help you (even if some details (notebook) have changed and others (Python 3) will change soon).</p>
<p>If you're not primarily a native English speaker, the original French version, or a German translation are also available via the same page.</p>
https://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/?comment=48014#post-id-48014**PS:** Would you mind sharing the references of your multivariate analysis textbook, apd possibly what you think of it ? This anwer could be of interest to many `Sage` would-be and beginning users...Sat, 21 Sep 2019 16:50:51 +0200https://ask.sagemath.org/question/47996/how-to-plot-multiple-tangent-lines-on-a-graph/?comment=48014#post-id-48014