Creating a MATLAB Plot with a varying variables?

47 visualizaciones (últimos 30 días)
Matlab12
Matlab12 el 20 de Sept. de 2015
Comentada: Ikenna Okoye el 28 de Nov. de 2018
Hey guys,
I have been asked by my organization to make a plot of the function y= x^m on MATLAB. I essentially have to use Matlab to plot the function f(x) = x^m for m = 1,2,3, and 4 on the same figure, as x runs from 1 to 2.
This is what I have so far:
clear all;
close all;
m= 1:1:4;
x=1:0.1:2;
y = x.^m;
xlabel ('value of x'); ylabel ( 'function value');
hold on plot(x,y);
However, when I execute the script, it returns the error "Matrix dimensions must match". Anyone know an alternative route?

Respuestas (2)

Walter Roberson
Walter Roberson el 20 de Sept. de 2015
y = bsxfun(@power, x.', m);

Matt J
Matt J el 20 de Sept. de 2015
Editada: Matt J el 20 de Sept. de 2015
x=1:0.1:2;
for m= 1:4;
xy{1,m}=x;
xy{2,m} = x.^m;
end
plot(xy{:});
xlabel ('value of x');
ylabel ('function value');
  1 comentario
Ikenna Okoye
Ikenna Okoye el 28 de Nov. de 2018
I wanted to do something similar, i have an equation for thrust,F_ava, that depends on two variables 'gamma' and 'ex' and has an outputed vector already, could do this to the code?:
for F_ava(1,:)
xy{1,F_ava} = gamma;
xy{2,F_ava} = ex;
xy{3,F_ava} = ((m_dot.*v_e)+ (P_e-P).*(A_t.*ex));
end
plot(xy{:});
xlabel ('Altitude (km)');
ylabel ('Thrust (N)');

Iniciar sesión para comentar.

Categorías

Más información sobre Graph and Network Algorithms 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