derivative

Sympy to numpy causes the AttributeError: 'Symbol' object has no attribute 'cos'

久未见 提交于 2019-12-01 12:45:58
I am trying to do partial derivatives using sympy and I want to convert it to a function so that I can substitute values and estimate the derivatives at some values of t_1, t_2. The code I am using is as follows: import sympy as sp import numpy as np from sympy import init_printing init_printing() t_1,t_2,X_1,X_2,Y_1,Y_2,X_c1,X_c2,Y_c1,Y_c2,a_1,a_2,psi_1,psi_2,b_1,b_2= sp.symbols('t_1 t_2 X_1 X_2 Y_1 Y_2 X_c1 X_c2 Y_c1 Y_c2 a_1 a_2 psi_1 psi_2 b_1 b_2') X_1=X_c1 + (a_1 * sp.cos(t_1) * sp.cos(psi_1)) - ((b_1) * sp.sin(t_1)* sp.sin(psi_1)) X_2=X_c2 + (a_2 * sp.cos(t_2) * sp.cos(psi_2)) - ((b_2)

Sympy to numpy causes the AttributeError: 'Symbol' object has no attribute 'cos'

≯℡__Kan透↙ 提交于 2019-12-01 10:54:24
问题 I am trying to do partial derivatives using sympy and I want to convert it to a function so that I can substitute values and estimate the derivatives at some values of t_1, t_2. The code I am using is as follows: import sympy as sp import numpy as np from sympy import init_printing init_printing() t_1,t_2,X_1,X_2,Y_1,Y_2,X_c1,X_c2,Y_c1,Y_c2,a_1,a_2,psi_1,psi_2,b_1,b_2= sp.symbols('t_1 t_2 X_1 X_2 Y_1 Y_2 X_c1 X_c2 Y_c1 Y_c2 a_1 a_2 psi_1 psi_2 b_1 b_2') X_1=X_c1 + (a_1 * sp.cos(t_1) * sp.cos

Saving derivative values in ode45 in Matlab

两盒软妹~` 提交于 2019-12-01 09:38:49
I'm simulating equations of motion for a (somewhat odd) system with mass-springs and double pendulum, for which I have a mass matrix and function f(x), and call ode45 to solve M*x' = f(x,t); I have 5 state variables, q= [ QDot, phi, phiDot, r, rDot]'; (removed Q because nothing depends on it, QDot is current.) Now, to calculate some forces, I would like to also save the calculated values of rDotDot, which ode45 calculates for each integration step, however ode45 doesn't give this back. I've searched around a bit, but the only two solutions I've found are to a) turn this into a 3rd order

Numerical derivative of a vector

霸气de小男生 提交于 2019-12-01 07:47:18
问题 I have a problem with numerical derivative of a vector that is x: Nx1 with respect to another vector t (time) that is the same size of x. I do the following (x is chosen to be sine function as an example): t=t0:ts:tf; x=sin(t); xd=diff(x)/ts; but the answer xd is (N-1)x1 and I figured out that it does not compute derivative corresponding to the first element of x. is there any other way to compute this derivative? 回答1: You are looking for the numerical gradient I assume. t0 = 0; ts = pi/10;

Finding the maximum gradient of a growth curve

﹥>﹥吖頭↗ 提交于 2019-12-01 05:56:26
问题 I have made a graph with four growth curves using ggplot2. Hopefully the code below should produce the graph if anyone wants to try. I want to find a value for the maximum slopes on each of the lines, taken over say 4 time points. Can anyone give any ideas how to go about this? library(ggplot2) dat <- structure(list(TIME = c(0L, 2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L, 18L, 20L, 22L, 24L, 26L, 28L, 30L, 0L, 2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L, 18L, 20L, 22L, 24L, 26L, 28L, 30L, 0L, 2L, 4L, 6L, 8L,

Derivative of an array in python?

*爱你&永不变心* 提交于 2019-11-30 15:00:00
Currently I have two numpy arrays: x and y of the same size. I would like to write a function (possibly calling numpy/scipy... functions if they exist): def derivative(x, y, n = 1): # something return result where result is a numpy array of the same size of x and containing the value of the n -th derivative of y regarding to x (I would like the derivative to be evaluated using several values of y in order to avoid non-smooth results). This is not a simple problem, but there are a lot of methods that have been devised to handle it. One simple solution is to used finite difference methods. The

3D Perlin noise analytical derivative

随声附和 提交于 2019-11-30 12:15:56
问题 I am currently implementing a 3D Perlin noise bump mapping using Shader Model 4 (DirectX 10 HLSL). Generating the noise itself is not a big problem (there are tons of tutorials and codes around) but what I have not found are analytical derivatives of 3D Perlin noise. The only sites taking the derivatives into account are Ińigo Quilez's site and a related GameDev.net discussion. The problem is that in the first link the noise is value based, not gradient based (which is a requirement for me),

numpy second derivative of a ndimensional array

陌路散爱 提交于 2019-11-30 12:04:37
问题 I have a set of simulation data where I would like to find the lowest slope in n dimensions. The spacing of the data is constant along each dimension, but not all the same (I could change that for the sake of simplicity). I can live with some numerical inaccuracy, especially towards the edges. I would heavily prefer not to generate a spline and use that derivative; just on the raw values would be sufficient. It is possible to calculate the first derivative with numpy using the numpy.gradient(

Java - Computation of Derivations with Apache Commons Mathematic Library

≡放荡痞女 提交于 2019-11-30 10:33:53
I have a problem in using the apache commons math library. I just want to create functions like f(x) = 4x^2 + 2x and I want to compute the derivative of this function --> f'(x) = 8x + 2 I read the article about Differentiation ( http://commons.apache.org/proper/commons-math/userguide/analysis.html , section 4.7). There is an example which I don't understand: int params = 1; int order = 3; double xRealValue = 2.5; DerivativeStructure x = new DerivativeStructure(params, order, 0, xRealValue); DerivativeStructure y = f(x); //COMPILE ERROR System.out.println("y = " + y.getValue(); System.out

Python differentiation using numpy not producing expected output

删除回忆录丶 提交于 2019-11-30 09:21:55
问题 So, I am working on some numerical computation. I have calculated some 100,000 points of a function ( return_times ) only computable numerically, and now want to take it's derivate using numpy.gradient . As I understand (doc), for an f(x)I can give the following arguments: numpy.gradient(arr_of_fx_datapoints, arr_of_their_x_values) to make it work. And that's what I (intended to) do. Except that it doesn't work. The result is almost (but not exactly) zero everywhere. The bug is reproduced by