필터 지우기
필터 지우기

why is my plot shows nothing?

조회 수: 6 (최근 30일)
geometry geometry
geometry geometry 2018년 3월 18일
댓글: geometry geometry 2018년 3월 18일
why is my plot shows nothing?
syms w
w=-1*10*pi:0.005:10*pi;
plot(w,sqrt(w.^2+w.^6)/(1+w.^4),'b');

채택된 답변

John D'Errico
John D'Errico 2018년 3월 18일
Because you need to read the getting started tutorials for MATLAB? In 3 simple (truly basic) lines of code, I see 4 significant errors, some worse than others.
syms w
You do not need to define w as a sym, if you will then overwrite it with a double. So the syms reference is a waste of time. More importantly, it suggests that you do not understand how MATLAB works with variables, that the next line which assigns w completely ignores the previous use of syms for w. So this is an error of comprehension.
w=-1*10*pi:0.005:10*pi;
Use linspace here, NOT colon to create a vector. The final element will not be 10*pi if you use colon. -1*10*pi is also silly, since -10*pi is equivalent.
plot(sqrt(w,w.^2+w.^6)/(1+w.^4),'b');
Several problems in this last line, even though I cannot even guess what you are trying to write.
sqrt(w,w.^2+w.^6) is a meaningless expression. I cannot even guess what you want to do there.
You know enough to use the .^ operator when w is a vector. You also need to learn about the .* and ./ operators for vectors. They are equally valuable and equally important.
It is vaguely possible that you really wanted to write this:
plot(w,sqrt(w.^2+w.^6)./(1+w.^4),'b');
But that would be a complete and wild guess on my part, and I tend to be a poor guesser.
So it is time for you to read the documentation.
  댓글 수: 1
geometry geometry
geometry geometry 2018년 3월 18일
Thanks! and sorry for my trivial mistakes; because I'm beginner in matlab.

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

추가 답변 (2개)

Birdman
Birdman 2018년 3월 18일
편집: Birdman 2018년 3월 18일
Replace
plot(sqrt(w,w.^2+w.^6)/(1+w.^4),'b')
with
plot(sqrt(w.^2+w.^6)./(1+w.^4),'b')
Also,
syms w
line is irrelevant since in second line, you overwrite it with a numeric vector. Therefore delete it.

Rik
Rik 2018년 3월 18일
Because the command you are using has an incorrect syntax. You can't enter two input arguments to sqrt.
Also, you first declare w as a sym, but then overwrite it with a vector. You also didn't provide an x vector to plot (it is not strictly necessary, but it is good coding practice). And as a last remark, did you mean to use a matrix division inside that plot function?

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by