Why the myfunction return zero elements?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Muna Shehan
el 17 de Jul. de 2016
Comentada: Muna Shehan
el 18 de Jul. de 2016
Hi all; I have a function which should return a R_gradient matrix. I identify its elements but when I call myfunction it returns zero elements. I checked the passing parameter kc there is nothing wrong with it and the values of the elements are calculated correctly when i calculated them separately (i.e. Rg22,....,Rg55). can any one explain what wrong with myfunction. Regards
function R_gradient = myfunction(kc)
r1 = 1e+5;
r2 = 0.5;
q = 1e-5;
ks = kc(1);
cs = kc(2);
param.ms = 325;
param.mus = 65;
param.kus = 232.5e3;
param.ct = 0 ;
Rg22=r2*(cs/param.ms)^2;
Rg23=-r2*(cs/param.ms)*(ks/param.ms);
Rg24=-r2*(cs/param.ms)^2;
Rg25=r2*cs/(param.ms^2);
Rg32=-r2*(cs/param.ms)*(ks/param.ms);
Rg33=r2*(ks/param.ms)^2;
Rg34=r2*(cs/param.ms)*(ks/param.ms);
Rg35=-r2*ks/(param.ms^2);
Rg42=-r2*(cs/param.ms)^2;
Rg43=r2*(cs/param.ms)*(ks/param.ms);
Rg44=r2*(cs/param.ms)^2;
Rg45=-r2*cs/(param.ms^2);
Rg52=r2*cs/(param.ms^2);
Rg53=-r2*ks/(param.ms^2);
Rg54=-r2*cs/(param.ms^2);
Rg55=q+r2/(param.ms^2);
R_gradient = [
r1 0 0 0 0;...
0 Rg22 Rg23 Rg24 Rg25;...
0 Rg32 Rg33 Rg34 Rg35;...
0 Rg42 Rg43 Rg44 Rg45;...
0 Rg52 Rg53 Rg54 Rg55];
end
0 comentarios
Respuesta aceptada
Star Strider
el 17 de Jul. de 2016
I don’t know what your ‘kc’ is, but when I do this:
kc = [1 2];
R_gradient = myfunction(kc)
I get this:
R_gradient =
1e+05 0 0 0 0
0 1.8935e-05 -9.4675e-06 -1.8935e-05 9.4675e-06
0 -9.4675e-06 4.7337e-06 9.4675e-06 -4.7337e-06
0 -1.8935e-05 9.4675e-06 1.8935e-05 -9.4675e-06
0 9.4675e-06 -4.7337e-06 -9.4675e-06 1.4734e-05
I don’t understand the problem. What do you want it to do?
2 comentarios
Star Strider
el 18 de Jul. de 2016
My pleasure.
I do not understand what you want your ‘myfunction’ to do. If you are doing nonlinear optimisation and want to check its convergence, I would use the norm function with a tolerance. It will approach zero but will likely not ever uniformly equal zero.
If you are doing nonlinear optimisation, you need to use the output of ‘myfunction’ to change the values of ‘kc’ in your code from iteration to iteration until the gradient approximates zero within an acceptable tolerance. (The usual default tolerance is 1.0E-8 in most such applications.)
I am guessing what you are doing. This is the best I can do.
Más respuestas (1)
Walter Roberson
el 17 de Jul. de 2016
If you getting out a matrix in which all except one entry are 0, then you need to give the command
format long g
and then look at the outputs again.
Ver también
Categorías
Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!