The least squares quadratic function is given as Code a Matlab program

7 visualizaciones (últimos 30 días)
The following data are given as the results of an experiment. The least squares quadratic function is given as Code a Matlab program that calculates the total squared error (E).
x = [5.435 4.635 3.835 3.035 2.325 1.435 0.635]
y = [1.00 1.28 1.70 2.20 2.97 4.35 7.50 ]
  3 comentarios
Walter Roberson
Walter Roberson el 20 de Mzo. de 2016
The question appears to be incomplete. It appears to be a copy and paste of an assignment but with a formula skipped.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 19 de Mzo. de 2016
I’m not certain what you want to do.
Here is one possibility:
x = [5.435 4.635 3.835 3.035 2.325 1.435 0.635];
y = [1.00 1.28 1.70 2.20 2.97 4.35 7.50 ];
p = polyfit(x, y, 2); % Quadratic Function Fit
v = polyval(p, x); % Evaluate
TSE = sum((v - y).^2); % Total Squared Error
figure(1)
plot(x, y, 'bp')
hold on
plot(x, v, '-r')
hold off
grid
  2 comentarios
Star Strider
Star Strider el 20 de Mzo. de 2016
My pleasure.
If my Answer solved your problem, please Accept it.
Star Strider
Star Strider el 26 de Mzo. de 2016
With respect to your re-titled Question: ‘what is different between while and for in matlab’:
A for loop sets a specific number of iterations at the outset:
for k1 = 1:10
... CODE ...
end
will run the code in the loop 10 times.
A while loop runs until a specific condition within the loop is met:
while q < 10
q = ...;
end
will run as many iterations as necessary until, in this example, ‘q’ is greater than or equal to 10, then the loop stops.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Performance and Memory en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by