Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

linear equation without coefficients

1 visualización (últimos 30 días)
Ana Monea
Ana Monea el 17 de Mayo de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
hello. so i am a beginner in matlab and i would need some help in solving a problem. I have 2 vectors x and y with 10 values each and the equation y=a*x+b. The task is to find the values for a and b. I know how to do this on paper, but i don t know how to code it. Please help.
  1 comentario
Ana Monea
Ana Monea el 18 de Mayo de 2020
Now i understand what you were saying. I was a bit confused, but now it s clear. Thank you!

Respuestas (1)

William Alberg
William Alberg el 17 de Mayo de 2020
I think the polyfit command is what you are looking for. It should work like this
k = polyfit(x,y,1)
a = k(1)
b = k(2)
  5 comentarios
Ana Monea
Ana Monea el 18 de Mayo de 2020
I understand now what you said thank you. And also on this exercise i have 10 values for x and z vectors and i have to find the c coefficient from z=c*sqrt(x). Can you help me on that too please?
William Alberg
William Alberg el 18 de Mayo de 2020
I have not tried that before. But it appears that the following code works.
F = @(x,xdata) x(1)*sqrt(xdata);
c = lsqcurvefit(F,0,x,z)
It can end up in a local minimum point, so you should be aware of that

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by