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!