필터 지우기
필터 지우기

Undefined function 'mtimes' for input arguments of type 'function_handle'.

조회 수: 60 (최근 30일)
So I'm very puzzled as to how I find out my C values from the C lin fit. It tells me define my formula's as function handles, no worries done that easy. Then it tells me perform least squares fit or nlinfit of my X function (the Tib model for distance). So I've laid it out in my code the same way I've done it before and I get the error you see in the title. Now I'm confused because X relies on A, and A relies on C. I tried doing an nlinfit on A to find C but no luck there. So I'm stuck on part a where things are highlighted.
I read others with similar errors and the soulition seemed to be pass something through your function, which I tried by
c = nlinfit(x,t,X(c,t),c0);
but that didn't work either, just told me c was an unknown variable.
clc
clear
%V(t) = @(t) A*(1-exp(c(1)*(t-t0); %speed Keller Model
%X(t) = @(t) A*(t-t0)-(A/c(1))*(1-exp(-c(1)*(t-t0)); %distance Keller Model
V = @(c, t) A*(1-exp(-c(1)*K))-c(2).*t; %speed
X = @(c, t) A*K-(c(1)/2)*K^2-(A/c(2))*(1-exp(-c(2)*K)); %Tibshirani model for distance
%time => 0.1; %minimum reaction time
A = @(c) (xe+c(1)/2)*(K^2)/(K-((1/c(2))*1-exp(-c(2)*K))); % A parameter, kept here untill script runs well
c0 = [.01;1;];
%--------------------------------------------------------------------------------------------------------%
c0 = [.01; 1]; %initial c parameters
load sprint.dat
x = sprint(:,1);
tbolt1 = sprint(:,2); %Time_Bolt_Beijing
tbolt2= sprint(:,3); %Time_Bolt_Berlin
tlewis1 = sprint(:,4); %Time_C.Lewis_Rome
tjohn1= sprint(:,4); %Time_B.Johnson_Rome
t0 = tbolt1(1);
te = tbolt1(11); %end time for bolt's first run in bejing
t = tbolt1;
K = te-t0; %shorens equation for bolt
xe = 100; %Ending distances for all runners
A = @(c) (xe+c(1)/2)*(K^2)/(K-((1/c(2))*1-exp(-c(2)*K))); % A parameter
V = @(c, t) A*(1-exp(-c(1)*K))-c(2).*t; %speed
X = @(c, t) A*K-(c(1)/2)*K^2-(A/c(2))*(1-exp(-c(2)*K)); %Tibshirani model for distance
%--------------------------------------------------------------------------------------------------------%
c = nlinfit(x,t,X,c0);

채택된 답변

Steven Lord
Steven Lord 2020년 9월 26일
You can't multiply a function handle and a number or two function handles.
You can multiply the result you get from evaluating a function handle and a number.
x = 0:360;
f = @sind;
g = @(x) 2*f(x);
figure('Name', 'g = @(x) 2*f(x)')
plot(x, g(x)) % works
h = @(x) 2*f;
figure('Name', 'h = @(x) 2*f')
plot(x, h(x))% does not work
You can multiply the values reurned by two function handles.
q = @(x) f(x).*g(x);
figure('Name', 'q = @(x) f(x).*g(x)')
plot(x, q(x))
  댓글 수: 1
Liam Crocker
Liam Crocker 2020년 9월 26일
I understand this example thank you, but am unsure how I would fix my coding here sorry!.
I can't multiply my X by the function handle A, I need to be multiplying the result I get from this. But the result of A relies on the values of C, which I dont know. So I tried to find C using the nlinfit for A, to help nail down a result of A to use with my X formula. It returns me this error:
Error using nlinfit (line 213)
Error evaluating model function '@(c)(xe+c(1)/2)*(K^2)/(K-((1/c(2))*1-exp(-c(2)*K)))'.
Error in Assignment2Q3 (line 29)
c = nlinfit(x,t,A,c0);
Caused by:
Error using Assignment2Q3>@(c)(xe+c(1)/2)*(K^2)/(K-((1/c(2))*1-exp(-c(2)*K)))
Too many input arguments.

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

추가 답변 (1개)

David Hill
David Hill 2020년 9월 26일
편집: David Hill 2020년 9월 26일
c = [.01; 1];
x = 0:10:100;
tbolt1 = [0.165,1.85,2.87,3.78,4.65,5.5,6.32,7.14,7.96,8.79,9.69];
t0 = tbolt1(1);
te = tbolt1(11);
t = tbolt1;
K = te-t0;
xe = 100;
A = @(c) (xe+c(1)/2*K^2)/(K-1/c(2)*(1-exp(-c(2)*K)));
V = @(c,t) A(c)*(1-exp(-c(2)*(t-t0)))-c(1)*t;
X = @(c, t) A(c)*(t-t0)-c(1)/2*(t-t0).^2-A(c)/c(2)*(1-exp(-c(2)*(t-t0)));
C= nlinfit(t,x,X,c);

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by