How can I take the f(y)th-order derivative of another function?

1 回表示 (過去 30 日間)
mikribs
mikribs 2017 年 7 月 28 日
編集済み: Karan Gill 2017 年 8 月 1 日
(R2011a) Hello, (I'm new to matlab) when using the diff function to take the nth order derivative of a function, one can use this syntax:
f = % some function of x %
d = diff( % function (f) to be differentiated % , % number (n) of times to differentiate %);
where n is some integer.
However, if I define a function of some other variable, namely :
s = ceil(y * (heaviside(y) - (2 * heaviside(y) * heaviside(-y))))
which outputs only non-negative integers, and then insert that function in place of n in the diff function, which looks like:
d = diff( % function of x to be differentiated % , s);
then the diff function will not differentiate our function (of x) s times, and will instead return some error on the line of where s is defined.
I am trying to create a 3D plot that displays the various s-order derivatives of and arbitrary function (of x), wherein each plane of the form y=n, where n is some integer, contains the nth order derivative of the function (of x).
How can I put some function of either and array or a symbol into the second parameter of the diff function in order to achieve what I want?
Thanks, Mike
This is ultimately what I'd like to run:
% First we define x and t as symbols, and y as an array.
syms x;
syms t;
y = linspace (-3,3);
% We also define a mesh so that we can late plot z as a function of both x
% and y.
[x,y] = meshgrid(x,y);
% Next we define some function of x.
f = x;
% Then we define the ceiling of the unit step function multiplied by y.
s = ceil(y * (heaviside(y) - (2 * heaviside(y) * heaviside(-y))));
% After that we define j as the sth-order derivative of f, where s is some
% integer
j = diff(f,s);
% Now we define the other factor of the integrand as L.
L = (x-t)^( -1 -y -s);
% Now we define the gamma function adjusted for our uses.
G = gamma( s - y );
% Now we define a function z as the integral from 0 to x of j multiplied by L with
% respect to t, all divided by G.
z = int(j*L,t,0,x)/G;
%Finally, we plot x, y, and z in a 3d mesh
ezsurf(z);
And here are the two errors I receive when I run it:
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> fracint at 14
s = ceil(y * (heaviside(y) - (2 * heaviside(y) * heaviside(-y))));
Should I have different definitions for x, y, and t than I currently do? Also, am I simply using incorrect syntax or is there a bigger problem (regarding the errors) than I know? Thanks, Mike

回答 (1 件)

Karan Gill
Karan Gill 2017 年 8 月 1 日
編集済み: Karan Gill 2017 年 8 月 1 日
Use .* instead of * , and for the why, look up those operators or simply search for your error Inner matrix dimensions must agree. and the results should explain what the fix is. Also, that's one error, not two. It looks like two because it's the error stack.

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by