Creating a MATLAB Plot with a varying variables?

44 vues (au cours des 30 derniers jours)
Matlab12
Matlab12 le 20 Sep 2015
Commenté : Ikenna Okoye le 28 Nov 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?

Réponses (2)

Walter Roberson
Walter Roberson le 20 Sep 2015
y = bsxfun(@power, x.', m);

Matt J
Matt J le 20 Sep 2015
Modifié(e) : Matt J le 20 Sep 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 commentaire
Ikenna Okoye
Ikenna Okoye le 28 Nov 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)');

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by