simple problem about plotting
8 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Image Analyst
on 8 Aug 2016
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 Comments
Image Analyst
on 8 Aug 2016
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!