help me about nlinfit

조회 수: 1 (최근 30일)
Garon0927
Garon0927 2018년 3월 16일
답변: Prajit T R 2018년 3월 19일
i want to solve nonlinear regression problem. input variable 'x' is two element. also output variable 'T' = two element.
but An error has occurred in matlab.
how can i solve it.
help me.....
here is my code.
clear all close all clc;
x(1,:) = 0:1:100; x(2,:) = 100:1:200; v = [4 8 5 3 ]; mdl = @(b,t)( b(1)*t.^3 + b(2)*t.^2 + b(3)*t + b(4)); T = mdl(v,x); S = mdl(v,x) + 10000*randn(1,101); beta0 = [0 0 0 0]; beta = nlinfit(x,S,mdl,beta0); %beta %result = mdl(beta,x);
figure(1) grid on hold on
plot(S','ro') %plot(result)6

채택된 답변

Prajit T R
Prajit T R 2018년 3월 19일
Hi Kim
The second argument to the nlinfit function only accepts a vector. So it would be better to fit 'x' element-wise. I have modified your code to illustrate the same. I am not sure if this is what you're looking for, but this might help:
x(1,:) = 0:1:100;
x(2,:) = 100:1:200;
v = [4 8 5 3 ];
mdl = @(b,t)( b(1)*t.^3 + b(2)*t.^2 + b(3)*t + b(4));
T = mdl(v,x);
S = mdl(v,x) + 10000*randn(1,101);
beta0 = [0 0 0 0];
size(x)
size(S)
beta1 = nlinfit(x(1,:),S(1,:),mdl,beta0);
beta2 = nlinfit(x(2,:),S(2,:),mdl,beta0);
result = mdl([beta1 beta2],x);
figure(1)
grid on
hold on
plot(S','ro')
figure
plot(result)
Cheers

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!