# Confusion in linearity?

I am studying linear systems from the book "Signals and Systems Laboratory with MATLAB". I have performed an example on MATLAB myself in this regard. Code is as follow:

clc
clear all
close all
t=-3:.1:3;
x1=sin(t);
x2=cos(t);
a1=2;
a2=3;
z=a1*x1+a2*x2;
y1=2*z+2*cos(pi*t/3)
plot(t,y1);
ylim([-1 11]);
figure;
z1=2*x1+2*cos(pi*t/3);
z2=2*x2+2*cos(pi*t/3)
y2=a1*z1+a2*z2;
plot(t,y2);
ylim([-1 19]);


When I run this program I get two figures containing two same shapes that are curve-like but amplitude/size/height is not same.

I am confused if my this system defined by equation y=2*z*cos(pi*t/3) used in program above is linear or not? If still yes, then why (as we have size difference in both curves)?

• I tried to improve the typesetting, but did not understand the last y= equation, and the actual question. Could you provide more details? – Laurent Duval Apr 11 '19 at 18:15
• dear@LaurentDuval . I for got to set both outputs with different names/identifier. I have now edited my code for clarification. So now y1 represents left hand side of linearity equation and y2 represents right hand side of linearity equation. As per requirement/law of linearity both sides of equation should be equal – engr Apr 12 '19 at 5:10
• i have highlighted linearity equation in attached photo – engr Apr 12 '19 at 5:40

## 2 Answers

To expand on Justme's reply:

From the looks of your code you seem to have confused what constitutes an LTI system.

In your code the LTI system that I see (y1=2*z) scales an undelayed input signal by 2. The additional 2*cos(pi/t) is NOT part of the system, it is in effect just another sinusoid that you have added to your signal - thus giving it an additional frequency component.

An LTI system can only ever do two things to an input complex signal - it can scale the magnitude and it can modify the phase of frequency components of the signal. It cannot modify the fundamental frequencies of the sinusoidal components of a signal. (NB: It can however create resonances that self-oscillate - this is however cause by recursion in the system)

Returning to your code once again, we see that you have checked the linearity property, but have also included a scaling of the additional sinusoid that you have misattributed as part of the system. If you remove this sinusoid in your system function, you will find that the linearity property holds for your system

Edit: Fixed some technical wording issues

But you have an error so y1 and y2 are not equal. There is only 2*cos(pi*t/3) in y1, but 10*cos(pi*t/3) in y2.