How solve linear equations

조회 수: 3 (최근 30일)
Cong Liu
Cong Liu 2020년 9월 24일
댓글: Bjorn Gustavsson 2020년 9월 25일
Hi everyone, I am working on a PhD assignement.
I need to solve a linear equation using matlab. The equation is listed below:
(Rb)^2*(xi)^2 + (Rb)^2*(X0)^2 + (Rb)^2*(xi)*(X0) + (Ra)^2*(yi)^2 + (Ra)^2*(Y0)^2 - (Ra)^2*(yi)*(Y0) - (Ra)^2*(Rb)^2 = 0;
I have 20 values of xi and yi, and I need to get the answers for X0, Y0, Ra, and Rb.
The examples on found on the internet are very simple linear equations which I am not so sure how to do it in my case.
Thank you!
  댓글 수: 4
Cong Liu
Cong Liu 2020년 9월 25일
편집: Cong Liu 2020년 9월 25일
https://ww2.mathworks.cn/matlabcentral/answers/599119-how-solve-linear-equations#comment_1022635
Hi Bjorn Gustavsson
Thank you for the response. yes, I am trying to fit parameters of an ellipse. I have a set of xi, yi data colllected from my experiment. Now I am trying to fit them into an sllipse. But first thing first, I need to calcualte the parameters.
Sorry I am new to this. What is the file exchange and how can it help me?
Bjorn Gustavsson
Bjorn Gustavsson 2020년 9월 25일
You will find a link to the file exchange in the top-left drop-down text-menu. It is a repository of all sorts of additional functions and toolboxes for matlab. You will find a lot of useful stuff on there, never avoid looking for solutions to your problems there, even if you dont find an exact full solution you will, almost guaranteed, find something that takes you a large step of the way. In addition to that, from your question it seems that you should spend a day or two to work through the getting started and introduction stuff on the site. Here's the direct link to the file exchange: fileexchange

댓글을 달려면 로그인하십시오.

답변 (1개)

Alan Stevens
Alan Stevens 2020년 9월 24일
편집: Alan Stevens 2020년 9월 24일
Here is one way of structuring your problem:
% Set initial values for Ra, Rb, X0, Y0
Guess = [Ra, Rb, X0, Y0]; % Use them to create initial guess
% Call solver with input arguments of Guess and the xi and yi data values.
[Values, Fval] = fminsearch(@fn,Guess,[],xi,yi);
% Extract values
Ra = Values(1);
Rb = Values(2);
X0 = Values(3);
Y0 = Values(4);
function F = fn(Guess,xi,yi)
Ra = Guess(1);
Rb = Guess(2);
X0 = Guess(3);
Y0 = Guess(4);
F1 = (Rb)^2*(xi).^2 + (Rb)^2*(X0)^2 + (Rb)^2*(xi)*(X0) ...
+ (Ra)^2*(yi).^2 + (Ra)^2*(Y0)^2 - (Ra)^2*(yi)*(Y0) ...
- (Ra)^2*(Rb)^2;
F = F1'*F1; % Assuming xi and yi are column vectors.
end

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by