How do I solve this integral in matlab?

1 件のコメント

Sam Chak
Sam Chak 2025 年 3 月 6 日
Hi @Aditya Zade, if you wish to call a specific user for help, you can use this special character "@".
You can also type out the integrand function in MATLAB by clicking the indentation icon .
For example
% declare symbols
syms t
% assign a value
w_g = 120*pi;
% create a function
func = - sin(w_g*t - pi/6)
func = 

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2025 年 3 月 6 日

0 投票

% declare symbols
syms t
Pi = sym(pi);
% assign a value
w_g = 2*Pi*60;
% create a function
func = - sin(w_g*t - Pi/6) .* sin(w_g*t) / sin(w_g * t - 2*Pi/3)
func = 
Integration = simplify(3*w_g/Pi * int(func, t, 0, 3*w_g, hold=true))
Integration = 
F = matlabFunction(Integration);
format long g
INT = F()
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.9e+04. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
INT =
-21492.6584717154

7 件のコメント

Sam Chak
Sam Chak 2025 年 3 月 6 日
@Aditya Zade, if you plot the integrand function, you can see the oscillatory singularities (division-by-zero) repeat at regular intervals along the time-axis.
w_g = 120*pi;
func = @(t) - sin(w_g*t - pi/6).*sin(w_g*t)./sin(w_g*t - 2*pi/3);
t = linspace(0, 0.1, 10001);
plot(t, func(t)), ylim([-250 250]), grid on
xlabel('Time')
Aditya Zade
Aditya Zade 2025 年 3 月 6 日
Hi @Sam Chak, thank you for the clarification. However, I am trying to integrate from t=0 to t=1/360 where the function is continuous. So, I thought I could integrate it.
Sam Chak
Sam Chak 2025 年 3 月 6 日
Mathematica also produced the same result as MATLAB. You can follow the example provided by @Walter Roberson. The integrand function is likely intended to differ from yours to encourage you to learn how to write the code independently.
This will reinforce your memory in learning how to calculate definite integrals (the area under a curve between two fixed limits) in MATLAB.
Sam Chak
Sam Chak 2025 年 3 月 6 日
@Aditya Zade, you can also try the integral() function.
% integrand
fun = @(x) 5*sech(5*x).^2;
lb = -1; % lower limit
ub = 1; % upper limit
% Evaluate the integral from x = -1 to x = 1.
q = integral(fun, lb, ub)
q = 1.9998
Aditya Zade
Aditya Zade 2025 年 3 月 6 日
編集済み: Sam Chak 2025 年 3 月 6 日
This did the job in matlab:
wg = 2 * pi * 60 ;
syms time real
func = -sin( ( wg * time ) - ( pi / 6 ) ) * sin( ( wg * time ) - ( pi / 6 ) ) * sin( wg * time ) / sin( ( wg * time ) - ( 2 * pi / 3 ) )
func = 
Integration = simplify( ( 3 * wg / pi ) * int( func, time, 0, pi / ( 3 * wg ) ), 1000 )
Integration = 
Thank you both of you for the help.
Aditya Zade
Aditya Zade 2025 年 3 月 6 日
This is what I am getting: 1/4 - (3*3^(1/2))/(8*pi)
Sam Chak
Sam Chak 2025 年 3 月 6 日
If you attempt to solve a mathematical equation or an integral problem using functions from the Symbolic Math Toolbox, the answers will be returned as symbolic expressions.
format long
Integration = 1/4 - (3*3^(1/2))/(8*pi)
Integration =
0.043251664216828

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by