How to integrate functions dependant on heaviside functions.

2 次查看(过去 30 天)
I'm trying to integrate the functions powerSquared and innerProduct but nothing seems o work. the following is my code:
clc
clear all
close all
t = linspace(0,4);
y = @(t) heaviside(t)-2*heaviside(t-2)+heaviside(t-4);
x = @(t) (t).*heaviside(t)-2*(t-1).*heaviside(t-1)+2*(t-3).*heaviside(t-3)-(t-4).*heaviside(t-4);
powerSquared = @(x) x.^2;
innerProduct = @(x,y) y.*x;
inner = integral(powerSquared,0,1)
energy = integral(innerProduct,0,1)
c = inner./energy

回答(1 个)

Walter Roberson
Walter Roberson 2018-4-1
innerProduct = @(x,y) y.*x is a function of two variables, but you are using integral() with it, which is the integral of a function of 1 variable.
It is confusing that you are using functions named x and y but you are using parameter names x and y.
My guess at what you want:
t = linspace(0,4);
y = @(t) heaviside(t)-2*heaviside(t-2)+heaviside(t-4);
x = @(t) (t).*heaviside(t)-2*(t-1).*heaviside(t-1)+2*(t-3).*heaviside(t-3)-(t-4).*heaviside(t-4);
powerSquared = @(t) x(t).^2;
innerProduct = @(t) y(t).*x(t);
inner = integral(powerSquared,0,1)
energy = integral(innerProduct,0,1)
c = inner./energy

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by