Undefined function 'mtimes' for input arguments of type 'function_handle'.
108 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Liam Crocker
am 26 Sep. 2020
Kommentiert: Liam Crocker
am 26 Sep. 2020
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);
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 26 Sep. 2020
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))
Weitere Antworten (1)
David Hill
am 26 Sep. 2020
Bearbeitet: David Hill
am 26 Sep. 2020
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);
Siehe auch
Kategorien
Mehr zu Gain Scheduling finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!