Azzera filtri
Azzera filtri

How to use the steepest descent method to solve a function to find the unknown parameters value

2 visualizzazioni (ultimi 30 giorni)
why it shows error,please fix this
ao=1;
bo=0.2;
co=0.1;
x = [0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
y= [455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
Sum=0
for i=1:10
S=((y(i)-(ao.*(exp(bo.x(i))+co.x(i)).^2)));
fun = @(y,x) (a*(exp(bx))+c*x);
Sum=Sum+S
end
Initial_S=Sum
coeffi_mat=[1 0.2 0.1];
%now calculating next coefficints and then finding new S, till the value of S<0.01
j=1
while S>0.01
S_to_a=0;
S_to_b=0;
S_to_c=0;
for i=1:10
Part_1=(y(i)-(coeffi_mat(j,1)).*exp(coeffi_mat(j,2)).x(i));
S_to_a_sum_2=-1.*exp(coeffi_mat(j,2)).x(i);
S_to_a_sum= Part_1.*S_to_a_sum_2;
S_to_a= S_to_a+ S_to_a_sum;
S_to_b_sum_2=-(coeffi_mat(j,1)).*x(i).*exp(coeffi_mat(j,2)).x(i);
S_to_b_sum= Part_1.*S_to_b_sum_2;
S_to_c_sum_2=-x(i);
S_to_c=Part_1.*S_to_c_sum_2;
end
S_to_a_final=2.*S_to_a
S_to_b_final=2.*S_to_b
S_to_c_final=2.*S_to_c
%%%%%%%%%5calculating gradient%%%%%%%%5
grad=sqrt((S_to_a_final).^2+(S_to_b_final).^2+(S_to_c_final).^2)
%%%%%%%%%%%calculating unit vectoresb%%%%%%%%555
uv_a=S_to_a_final/grad
uv_b=S_to_b_final/grad
uv_c=S_to_c_final/grad
%%%%%%%%calculating new coefficient %%%%%%%
%%%del=0.02
a= coeffi_mat(i,1)-(0.02*uv_a)
b= coeffi_mat(i,2)-(0.02*uv_b)
c= coeffi_mat(i,3)-(0.02*uv_c)
%%%% Appending new coefficient in coefficient matrix %%%%%%%%%5
coeffi_mat=[coeffi_mat;a,b,c]
%%%%%%%% calculating the value of S %%%%%%%%
for i=1:10
S_1=y(i)
S_2= (coeffi_mat(i+1,1).*exp(coeffi_mat(j+1,2).*1)+coeffi_mat(j+2,3).*1)
S=((S_1)-(S_2))^2
end
end
%%whn while loop will end, final value of Swill be found thn value of a,b,c
%%will be expected as
final_a=coeffi_mat(end,1)
final_b=coeffi_mat(end,2)
final_c=coeffi_mat(end,3)

Risposte (1)

Utkarsh Belwal
Utkarsh Belwal il 5 Ott 2020
Error is coming in the line number 8, I guess that you are trying to multiply two variables but are using the wrong operator for multiplying. You should use the * opeartor instead of the . operator. Replace line number 8 by this and the code should work fine:
S=((y(i)-(ao.*(exp(bo*x(i))+co*x(i)).^2)));
DISCLAIMER: These are my own views and in no way depict those of MathWorks.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by