derivative

Evaluating a symbolic function

半世苍凉 提交于 2020-03-15 09:37:29
问题 I want to find cos(5) . Why is this expression invalid: syms x f=sin(x) disp(diff(f)(5)) The error is Line: 3 Column: 12 Indexing with parentheses '()' must appear as the last operation of a valid indexing expression. 回答1: Your error has nothing to do with symbolic variables. It is caused by the statement diff(f)(5) - which is not something MATLAB syntax allows (as of R2019b). MATLAB interprets this as the user trying to access the 5th element of some intermediate result. If you want to know

Calculate the derivative of a vector

匆匆过客 提交于 2020-01-27 03:08:29
问题 I have the following function (Viviani's curve): Phi = @(t)[ cos(t)^2, cos(t)*sin(t), sin(t) ] Just a check that it's valid: s = linspace(0,T,1000); plot3(cos(s).^2, cos(s).*sin(s), sin(s)); How to derivate the function Phi (maybe multiple times), which represents Viviani's curve in a point t where t goes from 0 to 2*pi ? Did I defined Phi suitable for such a derivative? I've tried diff , but it did not keep the Phi as I would need it. If the second derivative would be Phi_d2 , I need to get

Calculate the derivative of a vector

a 夏天 提交于 2020-01-27 03:08:26
问题 I have the following function (Viviani's curve): Phi = @(t)[ cos(t)^2, cos(t)*sin(t), sin(t) ] Just a check that it's valid: s = linspace(0,T,1000); plot3(cos(s).^2, cos(s).*sin(s), sin(s)); How to derivate the function Phi (maybe multiple times), which represents Viviani's curve in a point t where t goes from 0 to 2*pi ? Did I defined Phi suitable for such a derivative? I've tried diff , but it did not keep the Phi as I would need it. If the second derivative would be Phi_d2 , I need to get

Can't convert expression to float

旧城冷巷雨未停 提交于 2020-01-24 12:33:30
问题 I'm trying to learn the ins and outs of symbolic manipulation in python (I'm a beginner). I have the following basic code, and the output is giving me an error telling me that it "can't convert expression to float". What's wrong with this code: from sympy import * from math import * def h(x): return log(0.75392 * x) x = symbols('x') hprime = h(x).diff(x) print(hprime) 回答1: This is a classic example of what is said in PEP-8 about wildcard imports: Wildcard imports ( from <module> import * )

Can't convert expression to float

十年热恋 提交于 2020-01-24 12:31:06
问题 I'm trying to learn the ins and outs of symbolic manipulation in python (I'm a beginner). I have the following basic code, and the output is giving me an error telling me that it "can't convert expression to float". What's wrong with this code: from sympy import * from math import * def h(x): return log(0.75392 * x) x = symbols('x') hprime = h(x).diff(x) print(hprime) 回答1: This is a classic example of what is said in PEP-8 about wildcard imports: Wildcard imports ( from <module> import * )

Constructing a Multidimensional Differentiation Matrix

元气小坏坏 提交于 2020-01-23 17:56:05
问题 I have been trying to construct the matrix D ij , defined as I want to plot it for points located at x i = -cos[ π (2 i + 1) / (2 N )] on the interval [-1,1] to consequentially take derivatives of a function. I am though having problems constructing the differentiating matrix D ij . I have written a python script as: import numpy as np N = 100 x = np.linspace(-1,1,N-1) for i in range(0, N - 1): x[i] = -np.cos(np.pi*(2*i + 1)/2*N) def Dmatrix(x,N): m_ij = np.zeros(3) for k in range(len(x)):

Trying to implement the difference formula in MATLAB

女生的网名这么多〃 提交于 2020-01-16 06:10:36
问题 Im trying to implement the difference formula f'(x) ≈ [ f(x+h) - f(x) ] / h using MATLAB for x=1 and h=10^-k , where k=0,...,16 . Furthermore, I want to plot the error. Below is my code. I see that the error is around 3, which I believe it too big. It should be close to 0. syms f(x) f(x) = tan(x); df = diff(f,x); x = 1; for k = 0:16 h = 10^-k; finitediff = double((f(x+h)-f(x))/h); err = double(abs(finitediff-df(x))); end 回答1: There is nothing wrong in your code, the finite difference formula

Derivative of a softmax function explanation

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 16:19:42
问题 I am trying to compute the derivative of the activation function for softmax. I found this : https://math.stackexchange.com/questions/945871/derivative-of-softmax-loss-function nobody seems to give the proper derivation for how we would get the answers for i=j and i!= j. Could someone please explain this! I am confused with the derivatives when a summation is involved as in the denominator for the softmax activation function. 回答1: The derivative of a sum is the sum of the derivatives, ie: d

Derivative of a softmax function explanation

浪子不回头ぞ 提交于 2020-01-11 16:16:27
问题 I am trying to compute the derivative of the activation function for softmax. I found this : https://math.stackexchange.com/questions/945871/derivative-of-softmax-loss-function nobody seems to give the proper derivation for how we would get the answers for i=j and i!= j. Could someone please explain this! I am confused with the derivatives when a summation is involved as in the denominator for the softmax activation function. 回答1: The derivative of a sum is the sum of the derivatives, ie: d