Hello Tyde,
It looks like you want to create a scaler field that encompasses every point in the ‘data.mat’ file.
In the current code, the ‘plot’ function attempts to generate a polynomial curve that best fits the data points while also minimizing error. Unfortunately, this approach did not successfully cover all points in the ‘data.mat’ file.
To achieve a comprehensive fit over all data points, here is a suggested approach:
- Start by applying the ‘fit’ function to the variables ‘speed’, ‘torque’ and ‘bsfc’.
f_ = fit([speed, torque], bsfc, 'poly23');
- Use the ‘meshgrid’ function to generate ‘speedGrid’ and ‘torqueGrid’. The ‘speedGrid’ represents a range of speed values, while the ‘torqueGrid’ represents a range of torque values. The combination of ‘speedGrid’ and ‘torqueGrid’ defines all the points the polynomial curve should encompass.
[speedGrid, torqueGrid] = meshgrid(linspace(min(speed), max(speed), 100), linspace(min(torque), max(torque), 100));
- Next, use the ‘feval’ function to compute ‘bsfc’ values for each point created by the combination of ‘speedGrid’ and ‘torqueGrid’.
bsfcScalarField = feval(f_, speedGrid, torqueGrid);
- Conclude by using a surface plot to display the polynomial curve.
surf(speedGrid, torqueGrid, bsfcScalarField);
title('BSFC Scalar Field - Surface Plot');
Following this method will produce the desired output, ensuring a fit that covers all specified points.
For more information on ‘meshgrid’, ‘feval’ and ‘surf’ function refer to below documentations:
Hope it helps!