integrate for long equation

13 visualizzazioni (ultimi 30 giorni)
GUILU
GUILU il 10 Apr 2024
Modificato: Sam Chak il 13 Apr 2024
can someone help me check my code , because i get the answer is not i expected. thanks
the orignal equation is:
code
syms p c A H T k z d x w t c2 v u pi
% Define symbolic expressions for v and u
v_expr = ((pi*H)/T)*(cosh(k*(z+d))/sinh(k*d))*cos(k*x-w*t);
u_expr = ((2*pi^2*H)/T^2)*(cosh(k*(z+d))/sinh(k*d))*sin(k*x-w*t);
% Define f using the symbolic expressions for v and u
f = p*(1+c)*A*u_expr + (1/2)*p*c2*v_expr*abs(v_expr);
% Compute the integral of f with respect to z
F = int(f,z)
  7 Commenti
GUILU
GUILU il 10 Apr 2024
thats what i get now
F =
piecewise(in((k*x - t*w)/pi - 1/2, 'integer') | H == 0 | cosh(k*(d + z)) == 0 | pi == 0, -(A*H*p*pi^2*sin(k*x - t*w)*sin(k*(d + z)*1i)*(c + 1)*2i)/(T^2*k*sinh(d*k)), 0 < H*pi*cos(k*x - t*w)*cosh(k*(d + z)) & ~in((k*x - t*w)/pi - 1/2, 'integer') & cosh(k*(d + z)) ~= 0, - (p*pi^2*((A*H*sin(k*x - t*w)*sin(k*(d + z)*1i)*(c + 1)*16i)/T^2 - (H^2*c2*sin(k*(d + z)*2i)*(sin(k*x - t*w)^2 - 1)*1i)/(T*abs(sin(d*k*1i))*abs(T)))*1i)/(8*k*sin(d*k*1i)) - (H^2*c2*p*pi^2*(sin(k*x - t*w)^2 - 1)*(d + z)*1i)/(4*T*abs(sin(d*k*1i))*sin(d*k*1i)*abs(T)), H*pi*cos(k*x - t*w)*cosh(k*(d + z)) < 0 & ~in((k*x - t*w)/pi - 1/2, 'integer') & cosh(k*(d + z)) ~= 0, - (p*pi^2*((A*H*sin(k*x - t*w)*sin(k*(d + z)*1i)*(c + 1)*16i)/T^2 + (H^2*c2*sin(k*(d + z)*2i)*(sin(k*x - t*w)^2 - 1)*1i)/(T*abs(sin(d*k*1i))*abs(T)))*1i)/(8*k*sin(d*k*1i)) + (H^2*c2*p*pi^2*(sin(k*x - t*w)^2 - 1)*(d + z)*1i)/(4*T*abs(sin(d*k*1i))*sin(d*k*1i)*abs(T)), ~in((k*x - t*w)/pi - 1/2, 'integer') & cosh(k*(d + z)) ~= 0 & ~in(H*pi*cos(k*x - t*w)*cosh(k*(d + z)), 'real'), int((2*A*H*p*pi^2*sin(k*x - t*w)*cosh(k*(d + z))*(c + 1))/(T^2*sinh(d*k)) + (H*c2*p*pi*abs(H*pi*cos(k*x - t*w)*cosh(k*(d + z)))*cos(k*x - t*w)*cosh(k*(d + z)))/(2*T*abs(sinh(d*k))*sinh(d*k)*abs(T)), z))
Aquatris
Aquatris il 10 Apr 2024
This is missing the D term:
f = p*(1+c)*A*u_expr + (1/2)*p*c2*v_expr*abs(v_expr);
So should be
f = p*(1+c)*A*u_expr + (1/2)*p*c2*v_expr*D*abs(v_expr);

Accedi per commentare.

Risposte (1)

Sam Chak
Sam Chak il 11 Apr 2024
You can DIVIDE the integrand and then CONQUER it. Once you've done that, you can validate the result by comparing it with your hand-calculated solution.
syms k z d mu1 mu2 mu3 mu4 nu1 nu2 nu3 nu4
assume(k > 0 & nu1 > 0 & nu2 > 0 & cosh(k*(z + d)) > 0)
%% Define symbolic expressions for v and u
% mu1 = (2*pi^2*H)/T^2; % constant
% mu2 = sin(k*x-w*t); % constant
% mu3 = p*(1 + c)*A; % constant
u = mu1*(cosh(k*(z + d))/sinh(k*d))*mu2
u = 
% nu1 = (pi*H)/T; % constant
% nu2 = cos(k*x-w*t); % constant
% nu3 = (1/2)*p*c2; % constant
v = nu1*(cosh(k*(z + d))/sinh(k*d))*nu2
v = 
% Define f using the symbolic expressions for v and u
f = mu3*u + nu3*v*abs(v)
f = 
% Compute the integral of f with respect to z
F = int(f, z)
F = 
F = simplify(F, 'steps', 100)
F = 
  2 Commenti
GUILU
GUILU il 13 Apr 2024
Thanks so much Sam
Sam Chak
Sam Chak il 13 Apr 2024
Modificato: Sam Chak il 13 Apr 2024
You are welcome, @GUILU. The key is to make MATLAB easy to interpret the "integrand" so that it can perform the integral efficiently. In your case, such that .
If you find the solution helpful, please consider clicking 'Accept' ✔ on the answer and voting 👍 for it. Your support is greatly appreciated!

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by