I need to plot the sum of 2 sine curves. I can successfully plot (x,y1) and plot(x,y2), they are smooth curves, however when i try to plot(x,y) where y = y1+y2 the curve comes out like this? how do i fix this i dont know what i am doing wrong? Thanks

댓글 수: 3

Stephen23
Stephen23 2021년 5월 11일
편집: Stephen23 2021년 5월 11일
"...however when i try to plot... the curve comes out like this"
You are plotting lots of zeros (to within floating point precision), because that is exactly what you calculated.
"how do i fix this i dont know what i am doing wrong?"
You need to consider the B factor. Note that for a B which is an integer multiple of 2*pi (and you defined B as 4*pi, which is clearly a multiple of 2*pi), the following identity holds true:
sin(B*X) = -sin(B*(1-X))
For example:
B = 2*pi;
X = rand(1,9);
sin(B*X)
ans = 1×9
-0.6044 -0.8824 -0.4910 -0.9397 -0.7891 0.9338 0.8413 0.9918 -0.9736
sin(B*(1-X))
ans = 1×9
0.6044 0.8824 0.4910 0.9397 0.7891 -0.9338 -0.8413 -0.9918 0.9736
That is why you are plotting zeros (or at least values very very very close to zero).
Stephen23
Stephen23 2021년 5월 16일
편집: Stephen23 2021년 5월 16일
Original question by Tyler Daines retrieved from Google Cache (unfortunately their deleted comments are not included):
Trying to plot a sine+sine function but not getting a smooth curve
I need to plot the sum of 2 sine curves. I can successfully plot (x,y1) and plot(x,y2), they are smooth curves, however when i try to plot(x,y) where y = y1+y2 the curve comes out like this? how do i fix this i dont know what i am doing wrong? Thanks
Rena Berman
Rena Berman 2021년 6월 29일

(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

답변 (2개)

DGM
DGM 2021년 5월 11일

0 개 추천

What you're looking at isn't meaningful. It's all just rounding error. You're essentially doing this:
y = sin(x) - sin(x);
I'm guessing there's some phase component that's not defined right yet, but I can't really guess at what you need it to be.
f = 2;
A = 1;
v = 1;
L = 1;
l = v/f;
B = (2*pi)/l;
w = 2*pi*f;
t = 0;
x = 0:0.0001:L;
z1 = A*sin(B*x - w*t);
z2 = A*sin(B*(L-x) - w*t);
y = z1+z2;
plot(x,z2); hold on
plot(x,z1);
For the future, please just paste your code using the code formatting tools. I had to retype all that and deal with the sub-pixel ambiguity differentiating the character '1' and 'l'.

댓글 수: 2

Tyler Daines
Tyler Daines 2021년 5월 11일
Sorry mate i havent used this forum before will do in the future.
DGM
DGM 2021년 5월 11일
No worries. It was short enough.

댓글을 달려면 로그인하십시오.

RAHUL MAURYA
RAHUL MAURYA 2021년 5월 12일

0 개 추천

clear all;
clc;
f = 2;
A = 1;
v = 1;
L = 1*(180/(pi));
l = v/f;
B = ((2*pi)/l)*(180/pi);
w = 2*pi*f;
t = 0;
x=0:0.0001:L;
z1 = (A*sind(B*x - w*t));
z2 = A*sind(B*(L-x) - w*t);
y=(z1+z2);
subplot(3,1,1);
plot(x,z1)
title('X,Z1')
axis([0 10 -1 1])
subplot(3,1,2);
plot(x,z2)
title('X,Z2')
axis([0 10 -1 1])
subplot(3,1,3);
plot(x,y)
title('X,Z1+Z2')
axis([0 10 -2 2])
Convert B and L in radian to degree.

질문:

2021년 5월 11일

편집:

2021년 6월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by