how to solve this

4 vues (au cours des 30 derniers jours)
daniel
daniel le 19 Jan 2023
Commenté : daniel le 19 Jan 2023
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.

Réponse acceptée

Image Analyst
Image Analyst le 19 Jan 2023
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 commentaire
daniel
daniel le 19 Jan 2023
tnks!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 19 Jan 2023
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 commentaires
daniel
daniel le 19 Jan 2023
but this is not interpolation
Walter Roberson
Walter Roberson le 19 Jan 2023
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, ...)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects 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