matlab words no help needed

4 ビュー (過去 30 日間)
Tyler Daines
Tyler Daines 2021 年 5 月 11 日
編集済み: Rena Berman 2021 年 6 月 29 日
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 件のコメント
Rena Berman
Rena Berman 2021 年 6 月 29 日

(Answers Dev) Restored edit

サインインしてコメントする。

回答 (3 件)

DGM
DGM 2021 年 5 月 11 日
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 件のコメント
DGM
DGM 2021 年 5 月 11 日
No worries. It was short enough.

サインインしてコメントする。


VBBV
VBBV 2021 年 5 月 11 日
編集済み: VBBV 2021 年 5 月 11 日
%if true
f = 2
f = 2
V = 1; A= 1; L = 1;
LL = V/f
LL = 0.5000
B = 2*pi/LL
B = 12.5664
t = 0; W = 2*pi*f
W = 12.5664
x = 0:0.0001:L;
z1 = A*sin(B*x-W*t)
z1 = 1×10001
0 0.0013 0.0025 0.0038 0.0050 0.0063 0.0075 0.0088 0.0101 0.0113 0.0126 0.0138 0.0151 0.0163 0.0176 0.0188 0.0201 0.0214 0.0226 0.0239 0.0251 0.0264 0.0276 0.0289 0.0302 0.0314 0.0327 0.0339 0.0352 0.0364
z2 = A*sin(B*(L-x)-W*t);
z = z1-z2
z = 1×10001
0.0000 0.0025 0.0050 0.0075 0.0101 0.0126 0.0151 0.0176 0.0201 0.0226 0.0251 0.0276 0.0302 0.0327 0.0352 0.0377 0.0402 0.0427 0.0452 0.0477 0.0503 0.0528 0.0553 0.0578 0.0603 0.0628 0.0653 0.0678 0.0704 0.0729
plot(x,z)
Use z1-z2 instead for smooth curve
  3 件のコメント
Stephen
Stephen 2021 年 5 月 13 日
"Does this mean that there is no way to plot y = ysrc + yref?"
I am not sure why you have reached that conclusion.
"I do see why my plot is meaningless."
The plot itself is not meaningless: you have correctly plotted lots of tiny values, because that is what you told MATLAB to plot. The values are numeric noise resulting from operations which are basically equivalent to X+(-X). MATLAB has correctly plotted that numeric noise (because it was all your numeric values are).
Important question: What do you expect to be plotted for X+(-X) ?
Perhaps you could scale the Y limits to suitable values then the numeric noise would not be noticeable at all.

サインインしてコメントする。


RAHUL MAURYA
RAHUL MAURYA 2021 年 5 月 12 日
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.
  1 件のコメント
RAHUL MAURYA
RAHUL MAURYA 2021 年 5 月 12 日
Convert B and L in degree from Radian

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by