# Plotting a function given a range of inputs

조회 수: 140(최근 30일)
Jesse Green 2018년 3월 6일
댓글: Vatsal Dhamelia 2020년 5월 11일
I need to plot a line of the Moody chart given a relative roughness and range of Reynolds numbers but I have no clue how to write a plot code. For simplicity, lets say I want to plot y=8x+10 with a range of 2<x<20. How would I go about doing this? Thank you.

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

### 답변(2개)

Elias Gule 2018년 3월 6일
First define your vector x as:
dx = 0.01;
x = 2:dx:20; % where dx in the increment from one x value to the other.
OR
N = 40; % number of samples
x = linspace(2,20,N);
then define y as:
y = 8*x + 10;
Then to plot:
plot(x,y);
For more help please look at the VERY USEFUL Matlab documentation. In the command window just type:
doc plot
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Vatsal Dhamelia 2020년 5월 11일

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

Star Strider 2018년 3월 6일
One possibility:
x = linspace(2, 20, 25);
y = 8*x + 10;
figure(1)
plot(x, y, '-pg')
grid
xlabel('x')
ylabel('y')
title('Moody Chart')
See the documentation for the various functions for details on their uses.

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

### Community Treasure Hunt

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

Start Hunting!

Translated by