Error during integration after differentiation

2 Ansichten (letzte 30 Tage)
MAK
MAK am 14 Nov. 2022
Bearbeitet: Dyuman Joshi am 14 Nov. 2022
%%
f = @(x,y,z) x.*y.^3.*z.^3; % define the input function
syms x;
g =diff(f,x)
Q = integral3(g,0,2,0,2,0,2) % LHS of divergence theorem
Invalid argument at position 1. First input argument must be a function handle.
Any one can help above , as i differeniate a function g and then would like to integate it , but it show without function handle

Antworten (2)

Dyuman Joshi
Dyuman Joshi am 14 Nov. 2022
Bearbeitet: Dyuman Joshi am 14 Nov. 2022
When you declare x as a symbolic variable, g will defined a symbolic variable as well. And as the error states, integral3 requires the input to be a function handle (which g is not)
f = @(x,y,z) x.*y.^3.*z.^3; % define the input function
syms x y z
g = diff(f,x)
g = 
class(g)
ans = 'sym'
You can integrate like this
%y and z should be syms variable as well to use int()
val = double(int(int(int(g,x,0,2),y,0,2),z,0,2))
val = 32
%verifying
h = @(x,y,z) y.^3.*z.^3;
q = integral3(h,0,2,0,2,0,2)
q = 32.0000
P.S - using matlabFunction will give a different answer, so you won't get the desired result with it and integral3()
G=matlabFunction(g)
G = function_handle with value:
@(y,z)y.^3.*z.^3

Askic V
Askic V am 14 Nov. 2022
Bearbeitet: Askic V am 14 Nov. 2022
Perhaps, this is what you asked for:
f = @(x,y,z) x.*y.^3.*z.^3; % define the input function
syms x;
g = diff(f,x);
% use eval function
h = @(x,y,z) eval(g)
h = function_handle with value:
@(x,y,z)eval(g)
Q = integral3(h,0,2,0,2,0,2) % LHS of divergence theorem
Q = 32.0000

Community Treasure Hunt

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

Start Hunting!

Translated by