How to find scalar field from a polynomial curve fit

4 visualizaciones (últimos 30 días)
Tyde Hilderbrandt
Tyde Hilderbrandt el 9 de Oct. de 2021
Respondida: Tejas el 25 de Abr. de 2024
Hey all,
I am new to Matlab and im trying to find a bsfc scalar feild to create a polynomial curved fit from this data.
speed=
1000
1500
2000
2500
3000
3500
4000
4500
5000
1000
1500
2000
2500
3000
3500
4000
4500
5000
1000
1500
2000
2500
3000
3500
4000
4500
5000
1000
1500
2000
2500
3000
3500
4000
4500
5000
1000
1500
2000
2500
3000
3500
4000
4500
5000
1000
1500
2000
2500
3000
3500
4000
4500
5000
1000
1500
2000
2500
3000
3500
4000
4500
5000
Torque
50
50
50
50
50
50
50
50
50
100
100
100
100
100
100
100
100
100
150
150
150
150
150
150
150
150
150
200
200
200
200
200
200
200
200
200
250
250
250
250
250
250
250
250
250
300
300
300
300
300
300
300
300
300
350
350
350
350
350
350
350
350
350
bsfc
375
400
398
400
420
450
500
505
575
290
300
295
320
325
340
340
385
400
262
270
263
274
275
275
310
335
350
252
248
248
247
255
265
283
312
323
270
235
236
240
240
262
280
290
305
300
275
245
240
242
258
280
283
290
325
320
325
318
327
325
290
285
280
here is my code so far
load('data.mat')
f_=fit([speed, torque],bsfc, 'poly23');
plot(f_,[speed, torque],bsfc);

Respuestas (1)

Tejas
Tejas el 25 de Abr. de 2024
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.
figure;
surf(speedGrid, torqueGrid, bsfcScalarField);
xlabel('Speed');
ylabel('Torque');
zlabel('BSFC');
title('BSFC Scalar Field - Surface Plot');
colorbar;
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!

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by