Undefined operator '>' for input arguments of type 'function_handle'. Error in simple_nlr (line 24) while err > tol
Mostrar comentarios más antiguos
clear all; close all; clc;
%Non Linear Regression
%Model: y = a1*a2^x
%measured data
xm = [50 450 780 1200 4400 4800 5300]';
ym = [28 30 32 36 51 58 69]';
if length(xm) ~= length(ym)
disp('error : xm and ym datasets have different sizes')
end
%define tolerance
tol = 1e-5;
%make intelligent initial guess
a0 = [1 1]
%compute function y
y = @(a) a(1)*a(2).^xm
err = @(a) sum((y(a) - ym).^2)
while err > tol
yopt = fmincon(err,a0);
end
%plots
plot (xm,ym,'ro')
hold on
plot (xm,y,'bx')
Please tell me how to rectify this error and to avoid future mistakes
Respuestas (2)
KALYAN ACHARJYA
el 20 de Oct. de 2019
Editada: KALYAN ACHARJYA
el 20 de Oct. de 2019
The err in your code is function handle
>> err
err =
function_handle with value:
@(a)sum((y(a)-ym).^2)
You are trying to compare it with numeric value (tol), read about compare function handle
Steven Lord
el 20 de Oct. de 2019
You don't want to ask if the function handle is greater than a certain value.
You want to ask if the result of evaluating the function handle at a certain point is greater than a certain value.
fh = @sin;
thisWillError = fh > 0.5
thisWillWork = fh(pi/2) > 0.5
Categorías
Más información sobre Support Vector Machine Regression en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!