simple problem about plotting

10 visualizaciones (últimos 30 días)
Geonhee LEE
Geonhee LEE el 8 de Ag. de 2016
Editada: Walter Roberson el 8 de Ag. de 2016
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!

Respuesta aceptada

Image Analyst
Image Analyst el 8 de Ag. de 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 comentarios
Image Analyst
Image Analyst el 8 de Ag. de 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.
Geonhee LEE
Geonhee LEE el 8 de Ag. de 2016
I got it!!
thank you for your kind answering!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by