How can I interpolate x and y data points in plot and slope (dy/dx) at any value of x?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MOHD UWAIS
el 27 de Feb. de 2023
clear all
clc
x=[15 20 25 30 35 40 45 50 55];
y=[11.89 11.845 11.85 11.855 11.865 11.93 12.01 12.2 12.77];
plot(x,y)
0 comentarios
Respuesta aceptada
Torsten
el 27 de Feb. de 2023
Editada: Torsten
el 27 de Feb. de 2023
x=[15 20 25 30 35 40 45 50 55];
y=[11.89 11.845 11.85 11.855 11.865 11.93 12.01 12.2 12.77];
% Approximate dy/dx
dy = gradient(y,5);
hold on
yyaxis left
plot(x,y)
ylabel('y vs. x')
yyaxis right
plot(x,dy)
ylabel('dy/dx vs. x')
hold off
grid on
% interpolate y and dy/dx at x=x0
x0 = 22;
y0 = interp1(x,y,x0)
dy0 = interp1(x,dy,x0)
3 comentarios
Torsten
el 27 de Feb. de 2023
Editada: Torsten
el 27 de Feb. de 2023
But you also didn't give us an equation for y in terms of x ... So isn't it natural that you also only get dy/dx as a vector of 9 values from the command dy = gradient(y,5) and that you have to interpolate between the values to get y and dy/dx for some given value of x in between 15 and 55 ?
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!