how to solve this

3 ビュー (過去 30 日間)
daniel
daniel 2023 年 1 月 19 日
コメント済み: daniel 2023 年 1 月 19 日
p=[101.3 106.6 109.4 114.7 116.9 118.2 123.7];
v=[1.69 3.67 4.37 5.45 5.84 6.05 6.90];
% 4 ways for interpolation
lin=interp1(v,p,5,'linear')
m=interp1(v,p,5,'makima')
sp=interp1(v,p,5,'spline')
n=interp1(v,p,5,'nearest')
% Display a graph of speed versus pressure, the graph will include the given measurements
as well as the results obtained using 4 methods interpolation.
Mark with a red asterisk the points where the speed is 5 [m/s.]
* Labels must be added to the axes, legend, grid lines and title.

採用された回答

Image Analyst
Image Analyst 2023 年 1 月 19 日
You almost got it. Maybe you just needed to read the manual some more and understand what is x and what is y.
p=[101.3 106.6 109.4 114.7 116.9 118.2 123.7];
v=[1.69 3.67 4.37 5.45 5.84 6.05 6.90];
plot(p, v, 'b.-', 'LineWidth', 2, 'MarkerSize', 20);
grid on;
xlabel('Pressure');
ylabel('Velocity');
% 4 ways for interpolation
xq = linspace(min(p), max(p), 500);
lin=interp1(p, v, xq,'linear') ;
m=interp1(p, v, xq,'makima');
sp=interp1(p, v, xq,'spline') ;
n=interp1(p, v, xq,'nearest');
% Find where speed is closest to 5
[value, index] = min(abs(lin - 5)) % Value is how far away from 5 the data point is.
value = 0.0029
index = 250
x5 = xq(index)
x5 = 112.4776
y5 = lin(index)
y5 = 4.9971
hold on;
yline(5, 'Color', 'r') % Horizontal red line at 5.
xline(x5, 'Color', 'r') % Horizontal red line at 5.
% Plot a red asterisk at the point closest to y=5
plot(x5, y5, 'r*', 'MarkerSize', 30, 'LineWidth', 2)
Go ahead and add the rest, like legend, title, etc.
  1 件のコメント
daniel
daniel 2023 年 1 月 19 日
tnks!

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 1 月 19 日
When you call plot, you can use
plot(x1, y1, x2, y2, x3, y3, ...)
where x1 and x2 and x3 and so on might happen to all be the same.
You can label using xlabel ylabel legend grid
  4 件のコメント
daniel
daniel 2023 年 1 月 19 日
but this is not interpolation
Walter Roberson
Walter Roberson 2023 年 1 月 19 日
plot(v,p,lin,m,sp,n,'r*',5)
That code asks to use v as the first independent variable, and plot p as dependent on it. And then to take lin as the next independent variable and plot m as depedent on it.
Contrast to
plot(v, p, v, lin, v, ...)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by