matrix dimensions do not agree?

조회 수: 1 (최근 30일)
john birt
john birt 2012년 4월 26일
how can I add more observed variables into a function 'f'
x = [1.4 1.5 1.6]; z=[4.1 5.3 6.7]; y = [0.2 0.31 0.43];
c = 0.1; %initial guess
t=0.1:0.1:1;
f = @(c,x) arrayfun(@(x)trapz(t,x.*c.*t.^2),x);
cfit = nlinfit(x,y,f,c)
works well, but trying to adapt the function to use more observed information in the form of the vector 'z' by coding
f = @(c,x) arrayfun(@(x)trapz(t,z+x.*c.*t.^2),x);
gives an error
??? Error using ==> nlinfit at 120
Error evaluating model function
'@(c,x)arrayfun(@(x)trapz(t,z+x.*c.*t.^2),x)'.
Error in ==> test88 at 6
cfit = nlinfit(x,y,f,c)
Caused by:
Error using ==> plus
Matrix dimensions must agree.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 4월 26일
x = [1.4 1.5 1.6]; z=[4.1 5.3 6.7]; y = [0.2 0.31 0.43];
c = 0.1; %initial guess
t=0.1:0.1:1;
f = @(c,x) arrayfun(@(x,z)trapz(t,x.*c.*t.^2),x,z);
cfit = nlinfit(x,y,f,c)
  댓글 수: 2
john birt
john birt 2012년 4월 26일
there is no 'z' in the trapz(t,x.*c.*t.^2) I was looking for trapz(t,z+x.*c.*t.^2)
john birt
john birt 2012년 4월 26일
it works!!!
clear;
x = [1.4 1.5 1.6]; z=[4.1 5.3 6.7]; y = [0.2 0.31 0.43]; n=size(x);
c = 0.1; %initial guess
t=0.1:0.1:1;
f = @(c,x) arrayfun(@(x,z)trapz(t,z+x.*c.*t.^2),x,z);
[cfit, r] = nlinfit(x,y,f,c)
error = sum(r.^2)/n(2)

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by