How to integrate functions dependant on heaviside functions.

2 visualizaciones (últimos 30 días)
Marco Ramirez
Marco Ramirez el 1 de Abr. de 2018
Respondida: Walter Roberson el 1 de Abr. de 2018
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

Respuestas (1)

Walter Roberson
Walter Roberson el 1 de Abr. de 2018
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

Community Treasure Hunt

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

Start Hunting!

Translated by