quad function

1 Ansicht (letzte 30 Tage)
Sudipta Basu
Sudipta Basu am 13 Mär. 2012
Hi, I am having difficulty using quad function as I am using it for the first time. I have a function, i (t) = 8e^-t/T sin(2*pi*t/T) for 0 ≤ t ≤ T/2 i (t) = 0 for T/2 ≤ t ≤ T I want to integrate it using quad function in MATLAB. I have written the following code syms T i= @(x)(8.*exp(-x/T).*sin((2*pi).*x/T))^2 Irms = ((quad(i,0,T/2) )^0.5)/T
But, MATLAB is giving the error ??? Error using ==> mupadmex Error in MuPAD command: not a square matrix [(Dom::Matrix(Dom::ExpressionField()))::_power]
Error in ==> sym.sym>sym.mpower at 198 B = mupadmex('mllib::mpower',A.s,p.s);
Error in ==> @(x)(8.*exp(-x/T).*sin((2*pi).*x/T))^2
Error in ==> quad at 77 y = f(x, varargin{:});
Can anyone tell me where am I wrong.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 13 Mär. 2012
i1 = @(t,T)(8*exp(-t/T).* sin(2*pi*t/T)).^2.*(t < T/2)
f1 = @(T)quad(@(t)i1(t,T),0,T/2)
% e.g. T = 10;
out = f1(10)
  2 Kommentare
Sudipta Basu
Sudipta Basu am 13 Mär. 2012
I have another query to this...Is it not possible that I will get a result in terms of T. I mean if I enter out=f1(T), it will given an expression in terms of T.
Alexander
Alexander am 14 Mär. 2012
The function 'quad' returns only doubles. You can use the Symbolic Math Toolbox to get an integral in terms of T:
syms x T
i = (8.*exp(-x/T).*sin((2*pi).*x/T))^2
Irms = ((int(i,0,T/2) )^0.5)/T
This gives:
Irms =
((64*pi^2*T*exp(-1)*(exp(1) - 1))/(4*pi^2 + 1))^(1/2)/T

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by