simple problem about plotting
조회 수: 10 (최근 30일)
이전 댓글 표시
hello guys;
I am trying to plot a mathematics graph..
The graph is
y=(x+895.185)*(42.036*sqrt(x+657.509)-1656.4)-42.036*sqrt(x+657.509)*(x+1790.37)+2234.91*x+2.484*10.^6;
I made a code for this like below.
x=(0:0.1:1000);
y=(x+895.185)*(42.036*sqrt(x+657.509)-1656.4)-42.036*sqrt(x+657.509)*(x+1790.37)+2234.91*x+2.484*10.^6;
but I got the error massage...
how can I solve it?
thank you!
댓글 수: 0
채택된 답변
Image Analyst
2016년 8월 8일
When you multiply a vector by another vector element by element, you need to use .* instead of * otherwise it tries to do a matrix multiplication. Fixed code:
y=(x+895.185).*(42.036*sqrt(x+657.509)-1656.4)-42.036*sqrt(x+657.509).*(x+1790.37)+2234.91*x+2.484*10.^6;
댓글 수: 3
Image Analyst
2016년 8월 8일
No. When you did
x=(0:0.1:1000);
you made a vector. The parentheses were optional and unneeded. You could just have well have done
x = 0 : 0.1 : 1000;
and that would have been a vector too. And of course "sqrt(x+657.509)" is also a vector, and "(x+895.185)" is also a vector, and so is "(x+1790.37)" and "2234.91*x". You do not need a dot if you're multiplying a scalar (single number) times a vector, just when you want to multiply two vectors element by element, and of course they need to be the same length.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!