Find Coefficients of an equation

조회 수: 3 (최근 30일)
Learning
Learning 2024년 2월 18일
답변: Star Strider 2024년 2월 18일
Hi, I have a table containing 3 columns of data. I also have an equation with 4 unknown coefficients. How do I fit/solve the equation using the table data to obtain the unknown coefficients using Matlab?
Thanks!
  댓글 수: 2
Torsten
Torsten 2024년 2월 18일
Why three columns and not two ? Do you have two independent variables in your equation:
column3 = f(column1,column2)
?
Learning
Learning 2024년 2월 18일
Thanks for responding. Yes I have 2 independent variables.

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

채택된 답변

Star Strider
Star Strider 2024년 2월 18일
Using two independent variables is relatively straightforward. You need to concatenate them, then refer to them individually inside the objective function.
Data = randn(10,3);
objfcn = @(b, xy) b(1).*exp(-((xy(:,1)-b(2)).^2+(xy(:,2)-b(3)).^2)*b(4));
xy = Data(:,[1 2]);
[B,resnrm] = fminsearch(@(b)norm(Data(:,3) - objfcn(b,xy)), rand(4,1))
Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 2.628093
B = 4×1
-2.9726 1.7228 0.1193 9.6214
resnrm = 2.6281
N = 25;
x = linspace(min(Data(:,1)), max(Data(:,1)), N);
y = linspace(min(Data(:,2)), max(Data(:,2)), N);
[X,Y] = ndgrid(x,y);
fitfcn = @(b,X,Y) b(1).*exp(-((X-b(2)).^2+(Y-b(3)).^2)*b(4));
Z = fitfcn(B,X,Y);
figure
scatter3(Data(:,1), Data(:,2), Data(:,3), 'filled')
hold on
surf(X, Y, Z, 'FaceAlpha',0.5)
hold off
colormap(turbo)
This is a random example.
.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by