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 Comments

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 on 10 Apr 2024
Edited: Sam Chak on 10 Apr 2024
thanks for reply
this is my equation .
i am expecting another equation F should be simial with i calcualte by hand
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)
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
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
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))
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);

Sign in to comment.

Answers (1)

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 Comments

Thanks so much Sam
Sam Chak
Sam Chak on 13 Apr 2024
Edited: Sam Chak on 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!

Sign in to comment.

Asked:

on 10 Apr 2024

Edited:

on 13 Apr 2024

Community Treasure Hunt

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

Start Hunting!