Non linear curve
3 次查看(过去 30 天)
显示 更早的评论
Dear all,
How can we plot nonlinear curve connecting set of data points in vector spaces.
4 个评论
Oleg Komarov
2011-6-1
Edit your post adding the code inside the cody and formatting it properly: http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question
John
2024-5-9
编辑:John
2024-5-9
To plot a nonlinear curve connecting a set of data points in vector spaces , you can use the spline function along with plot. example:
% Data points
x = [-1, 0, 1, 2, 3];
y = [2, 1, 3, 2, 4];
% Generate a fine mesh of points for the curve
x_fine = linspace(min(x), max(x), 100);
% Interpolate using spline
y_fine = spline(x, y, x_fine);
% Plot the data points and the curve
plot(x, y, 'o', 'MarkerSize', 8, 'MarkerFaceColor', 'blue');
hold on;
plot(x_fine, y_fine, 'r-', 'LineWidth', 2);
xlabel('x');
ylabel('y');
title('Nonlinear Curve Connecting Data Points');
legend('Data Points', 'Curve');
grid on;
- define the data points as vectors x and y.
- generate a fine mesh of points x_fine using linspace to create a smooth curve. The number of points can be adjusted as needed.
- use the spline function to interpolate the data points. It takes the original x and y data points and the fine mesh x_fine as inputs and returns the corresponding interpolated values y_fine.
- plot the data points using plot with circular markers ('o') in blue color.
- use hold on to keep the current plot and add the curve on top of it.
- plot the curve using plot with the fine mesh points x_fine and y_fine, specifying a red solid line ('-') with a line width of 2.
- add labels for the x-axis, y-axis, and title using xlabel, ylabel, and title, respectively.
- add a legend to identify the data points and the curve using legend.
- Finally, add a grid to the plot using grid on.
This code will produce a plot with the data points connected by a smooth nonlinear curve. The spline function is used for interpolation, which generates a piecewise polynomial curve that passes through all the data points.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Chemical Spectroscopy 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!