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 Center および File Exchange회귀 についてさらに検索

Community Treasure Hunt

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

Start Hunting!