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?

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 6월 13일

0 개 추천

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

카테고리

제품

질문:

2021년 6월 13일

답변:

2021년 6월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by