integrate for long equation

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 comentarios

Dyuman Joshi
Dyuman Joshi el 10 de Abr. de 2024
The equations are not clear (atleast to me), as there are symbols missing.
Please post the equations in text format or attach a picture.
Also, specify what the expected answer/output is.
GUILU
GUILU el 10 de Abr. de 2024
Editada: Sam Chak el 10 de Abr. de 2024
thanks for reply
this is my equation .
i am expecting another equation F should be simial with i calcualte by hand
Liam
Liam el 10 de Abr. de 2024
In your expression for V the first term does not match the equation.
v_expr = (pi*H/T)*(cosh(k*(z+d))/sinh(k*d))*sin(k*x-w*t)
GUILU
GUILU el 10 de Abr. de 2024
thanks i just updated the code but sitll show me like this
piecewise(in((k*x - t*w)/pi - 1/2, 'integer') | H == 0 | cosh(k*(d + z)) == 0, -(A*H*p*sin(k*x - t*w)*sin(k*(d + z)*1i)*(c + 1)*2778046668940015i)/(140737488355328*T^2*k*sinh(d*k)), ~in((k*x - t*w)/pi - 1/2, 'integer') & 0 < H*cos(k*x - t*w)*cosh(k*(d + z)) & cosh(k*(d + z)) ~= 0, - (p*((A*H*sin(k*x - t*w)*sin(k*(d + z)*1i)*(c + 1)*2778046668940015i)/T^2 - (H^2*c2*pi^2*sin(k*(d + z)*2i)*(sin(k*x - t*w)^2 - 1)*17592186044416i)/(T*abs(sin(d*k*1i))*abs(T)))*1i)/(140737488355328*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') & H*cos(k*x - t*w)*cosh(k*(d + z)) < 0 & cosh(k*(d + z)) ~= 0, - (p*((A*H*sin(k*x - t*w)*sin(k*(d + z)*1i)*(c + 1)*2778046668940015i)/T^2 + (H^2*c2*pi^2*sin(k*(d + z)*2i)*(sin(k*x - t*w)^2 - 1)*17592186044416i)/(T*abs(sin(d*k*1i))*abs(T)))*1i)/(140737488355328*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') & ~in(H*cos(k*x - t*w)*cosh(k*(d + z)), 'real') & cosh(k*(d + z)) ~= 0, int((2778046668940015*A*H*p*sin(k*x - t*w)*cosh(k*(d + z))*(c + 1))/(140737488355328*T^2*sinh(d*k)) + (H*c2*p*pi^2*cos(k*x - t*w)*cosh(k*(d + z))*abs(H*cos(k*x - t*w)*cosh(k*(d + z))))/(2*T*abs(sinh(d*k))*sinh(d*k)*abs(T)), z))
dont know what that means
Liam
Liam el 10 de Abr. de 2024
Add pi to the list of symbolic variables, it will clean up the output lots.
syms p c A H T k z d x w t c2 v u pi
GUILU
GUILU el 10 de Abr. de 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 el 10 de Abr. de 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);

Iniciar sesión para comentar.

Respuestas (1)

Sam Chak
Sam Chak el 11 de Abr. de 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 comentarios

GUILU
GUILU el 13 de Abr. de 2024
Thanks so much Sam
Sam Chak
Sam Chak el 13 de Abr. de 2024
Editada: Sam Chak el 13 de Abr. de 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!

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 10 de Abr. de 2024

Editada:

el 13 de Abr. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by