Hi Delika,
I understand that you've using the Curve Fitter app to fit a curve to a set of data. And you would like to mark the tangent lines at particular points on this curve.
This can be done manually by using the equation of the fit created by the Curve Fitter app. The steps to be follwed are listed below:
- Export the fit from the Curve Fitter app to the Workspace, using the "Export" option in the app's toolstrip. Assume the fit object is named "fitResult".
- Once we have the equation of the fit, we need to find the derivative. I will assume that the fit is polynomial, for which the derivative is already well known. You can use symbolic computation to find the equation of the derivative in general. Refer to the documentation of the "diff" function in MATLAB: https://www.mathworks.com/help/releases/R2020a/symbolic/diff.html
coeffs = coeffvalues(fitResult);
- Now we can calculate the slope of these tangent lines, and plot these lines at the specified points.
x_range = linspace(min(x_data), max(x_data), 1000);
plot(x_data, y_data, 'ro');
plot(x_range, fitResult(x_range), 'b-');
for i = 1:length(x_points)
y_tan = fitResult(x_tan);
x_tangent = linspace(x_tan-1, x_tan+1, 100);
y_tangent = slope*x_tangent + c;
plot(x_tangent, y_tangent, 'k--', 'LineWidth', 2);
Hope this helps!
-Shivang