Re: SciPy-User Digest, Vol 231, Issue 1
Robert Kern <[email protected]> Mon, 23 Jan 2023 14:56:44 -0500
| Newsgroups | gmane.comp.python.scientific.user |
|---|---|
| Message-ID | <CAF6FJiv_YejBiZ7TWvg9uRzcB6dx_PMnSaGAPcEqQTUV85NpsA@mail.gmail.com> |
--===============2617348300183595835== Content-Type: multipart/alternative; boundary="000000000000fdaf9a05f2f3cd43" --000000000000fdaf9a05f2f3cd43 Content-Type: text/plain; charset="UTF-8" On Mon, Jan 23, 2023 at 1:29 PM Samuel Dupree <[email protected]> wrote: > The problem I have is if the interpolator only sees numbers. Unless > there is some undercover means by which the interpolator sees the > function used to generate the numbers passed to it, how does it know the > conversion factor is used argument to the sine function? Furthermore, If > I were to rewrite the program as follows, I still get the same results. > > > > import numpy as np > import matplotlib.pyplot as plt > from scipy.interpolate import pchip_interpolate > > x_observed = np.linspace(0.0, 360.0, 100) > xx_observed = np.pi*x_observed/180 > > y_observed = np.sin(xx_observed) > dydx_observed = np.cos(xx_observed) > Note that this is *not* a derivative of `y_observed` with respect to `x_observed`. It is the derivative with respect to the *transformed variable* `xx_observed`. If you want the derivative against `x_observed`, you will have to apply the chain rule and scale the value from `np.cos()` appropriately. x = np.linspace(min(x_observed), max(x_observed), num=100) > y = pchip_interpolate(x_observed, y_observed, x, der=0, axis=0) > dydx = pchip_interpolate(x_observed, y_observed, x, der=1, axis=0) > This, on the other hand, is the derivative of `y` with respect to `x_observed`. Thus, you cannot compare `dydx` directly to `dydx_observed`. They will differ by the scale factor that you would get from applying the chain rule correctly. -- Robert Kern --000000000000fdaf9a05f2f3cd43 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr">On Mon, Jan 23, 2023 at 1:29 PM Samuel Du= pree <<a href=3D"mailto:[email protected]">[email protected]</a>= > wrote:<br></div><div class=3D"gmail_quote"><blockquote class=3D"gmail_= quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,= 204);padding-left:1ex">The problem I have is if the interpolator only sees = numbers. Unless <br> there is some undercover means by which the interpolator sees the <br> function used to generate the numbers passed to it, how does it know the <b= r> conversion factor is used argument to the sine function? Furthermore, If <b= r> I were to rewrite the program as follows, I still get the same results.<br> <br> <br> <br> import numpy as np<br> import matplotlib.pyplot as plt<br> from scipy.interpolate import pchip_interpolate<br> <br> x_observed=C2=A0=C2=A0=C2=A0 =3D np.linspace(0.0, 360.0, 100)<br> xx_observed=C2=A0=C2=A0 =3D np.pi*x_observed/180<br> <br> y_observed=C2=A0=C2=A0=C2=A0 =3D np.sin(xx_observed)<br> dydx_observed =3D np.cos(xx_observed)<br></blockquote><div><br></div><div>N= ote that this is <i>not</i> a derivative of `y_observed` with respect to `x= _observed`. It is the derivative with respect to the <i>transformed variabl= e</i> `xx_observed`. If you want the derivative against `x_observed`, you w= ill have to apply the chain rule and scale the value from `np.cos()` approp= riately.</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"mar= gin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1= ex"> x=C2=A0=C2=A0=C2=A0 =3D np.linspace(min(x_observed), max(x_observed), num= =3D100)<br> y=C2=A0=C2=A0=C2=A0 =3D pchip_interpolate(x_observed, y_observed, x, der=3D= 0, axis=3D0)<br> dydx =3D pchip_interpolate(x_observed, y_observed, x, der=3D1, axis=3D0)<br= ></blockquote><div><br></div><div>This, on the other hand, is the derivativ= e of `y` with respect to `x_observed`. Thus, you cannot compare `dydx` dire= ctly to `dydx_observed`. They will differ by the scale factor that you woul= d get from applying the chain rule correctly.</div><div><br></div></div>-- = <br><div dir=3D"ltr" class=3D"gmail_signature">Robert Kern</div></div> --000000000000fdaf9a05f2f3cd43-- --===============2617348300183595835== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ SciPy-User mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/scipy-user.python.org/ Member address: [email protected] --===============2617348300183595835==--