MATLAB Answers

0

How to integrate functions dependant on heaviside functions.

Asked by Marco Ramirez on 1 Apr 2018
Latest activity Answered by Walter Roberson
on 1 Apr 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

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 1 Apr 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

  0 Comments

Sign in to comment.