MATLAB Answers

Plotting a function given a range of inputs

675 ビュー (過去 30 日間)
Jesse Green
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
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.
N = 40; % number of samples
x = linspace(2,20,N);
then define y as:
y = 8*x + 10;
Then to plot:
For more help please look at the VERY USEFUL Matlab documentation. In the command window just type:
doc plot
  2 件のコメント
Vatsal Dhamelia
Vatsal Dhamelia 2020 年 5 月 11 日
can you please help me fo plot KC vs Pam


Star Strider
Star Strider 2018 年 3 月 6 日
One possibility:
x = linspace(2, 20, 25);
y = 8*x + 10;
plot(x, y, '-pg')
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