Non linear curve

3 次查看(过去 30 天)
IEEE IE
IEEE IE 2011-6-1
编辑: John 2024-5-9
Dear all,
How can we plot nonlinear curve connecting set of data points in vector spaces.
  4 个评论
Oleg Komarov
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
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;
  1. define the data points as vectors x and y.
  2. generate a fine mesh of points x_fine using linspace to create a smooth curve. The number of points can be adjusted as needed.
  3. 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.
  4. plot the data points using plot with circular markers ('o') in blue color.
  5. use hold on to keep the current plot and add the curve on top of it.
  6. 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.
  7. add labels for the x-axis, y-axis, and title using xlabel, ylabel, and title, respectively.
  8. add a legend to identify the data points and the curve using legend.
  9. 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 CenterFile Exchange 中查找有关 Chemical Spectroscopy 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by