Creating a MATLAB Plot with a varying variables?

조회 수: 44 (최근 30일)
Matlab12
Matlab12 2015년 9월 20일
댓글: Ikenna Okoye 2018년 11월 28일
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?

답변 (2개)

Walter Roberson
Walter Roberson 2015년 9월 20일
y = bsxfun(@power, x.', m);

Matt J
Matt J 2015년 9월 20일
편집: Matt J 2015년 9월 20일
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
Ikenna Okoye
Ikenna Okoye 2018년 11월 28일
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)');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by