linear regression , Grid search
Show older comments
I try to solve this linear system then to tray to do the same thing with Grid search method
function Gred_Search5()
clear
clc
close all
x=[1 ;2 ;3 ;4 ;5]; % die Matrix der Angaben am X Achse
y=[1 ;1 ;4 ;3 ;6]; % die Matrix der Angaben am y Achse
plot(x,y,'bo')
xlim([0 8])
ylim([0 8])
hold on
%%
step_size= 0.05 ;
x0=0 ;
while step_size > 0.01
%% these are three sample points I'd like to check
xsamples = [x0-step_size x0 x0+step_size];
%% these is the function evaluated at my samp,e points
fsamples = f(xsamples);
%%% this is the minimum of the tree
fmin =min(fsamples);
%%% this is the vector location of my minimum
loc = (fmin==fsamples) ; %%% this is a vector of 0's and 1's
x0= xsamples(loc); %%% Grabbing the x that computs fmin = f(x)
plot (x0 , f(x0), 'r*','MarkerSize',10)
pause(1.0)
end
end
function P_pre=f(x,y)
N=length(x);
G =[ones(N,1),x];
d_obs=y;
Gtr=G' ;
m_est= inv(G'* G)* G'*d_obs;
disp(m_est);
P_pre= G * m_est;
end
how I can fix this code?
Answers (1)
Sulaymon Eshkabilov
on 13 Jun 2021
There are a few errs that need to be fixed, see the given comments:
function Gred_Search5()
clear
clc
close all
x=[1 ;2 ;3 ;4 ;5]; % die Matrix der Angaben am X Achse
y=[1 ;1 ;4 ;3 ;6]; % die Matrix der Angaben am y Achse
plot(x,y,'bo')
xlim([0 8])
ylim([0 8])
hold on
%%
step_size= 0.05 ;
x0=0 ;
while step_size > 0.01 % ERR: while loop has to be fixed. step_size value to be recomputed inside the loop
%% these are three sample points I'd like to check
xsamples = [x0-step_size x0 x0+step_size]; % ERR: size of xsamples is 3 while size of y is 5 as defined above
%% these is the function evaluated at my samp,e points
fsamples = f(xsamples); % ERR: f(x, y) requires two inputs
%%% this is the minimum of the tree
fmin =min(fsamples); % ERR:
%%% this is the vector location of my minimum
loc = (fmin==fsamples) ; %%% this is a vector of 0's and 1's % ERR:
x0= xsamples(loc); %%% Grabbing the x that computs fmin = f(x)
plot (x0 , f(x0), 'r*','MarkerSize',10) % ERR: f(x, y)
pause(1.0)
end
end
function P_pre=f(x,y) % NOTE: two inputs are required
N=length(x);
G =[ones(N,1),x];
d_obs=y;
Gtr=G' ;
m_est= inv(G'* G)* G'*d_obs;
disp(m_est);
P_pre= G * m_est;
end
Categories
Find more on Design of Experiments (DOE) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!