a and b constant

조회 수: 3 (최근 30일)
MOHAMED YHYA
MOHAMED YHYA 2019년 4월 21일
답변: Image Analyst 2019년 4월 21일
HI, im new to matlab and was wondering how would you input a command to help me solve an unknown constant in an equation.
I have a bunch of x,y points,The equation would be x= a*y+b

채택된 답변

Image Analyst
Image Analyst 2019년 4월 21일
You say "The equation would be x= a*y+b" and this is the opposite to the way people usually do things, but it can be done. Just reverse x and y when you call polyfit(). Try this:
coefficients = polyfit(y, x, 1); % x as a function of y - note NOT the usual way people do things!
a = coefficients(1)
b = coefficients(2)

추가 답변 (1개)

Stephan
Stephan 2019년 4월 21일
편집: Stephan 2019년 4월 21일
% Only needed if x,y are not column vectors
x = reshape(x,[],1);
y = reshape(y,[],1);
% solve for a, b
x = [x, ones(numel(x),1)];
sol = y\x;
a = sol(1);
b = sol(2);

카테고리

Help CenterFile Exchange에서 Christmas / Winter에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by