my array don't return the true value

1 vue (au cours des 30 derniers jours)
tuan nguyen minh
tuan nguyen minh le 26 Oct 2021
i use this function:
function f =hpt(u1,u2,u3,u4,u5)
global P X G m Y mz_0 Cy Xt Xf mz_delta_b delta_b mz_omega_z b_a q S I_z;
f=[ (P*cos(-0.014)-X-G*sin(u2))/m,...
(P*sin(-0.014)+Y-G*cos(u2))/(m*u1),...
((mz_0+Cy*(Xt-Xf)+mz_delta_b*delta_b+mz_omega_z*b_a*(u3/u1))*q*S*b_a)/I_z,...
u3,...
u1*sin(u2)
];
end
with the input
gt_dau(1,:)=[V small_theta omega_z theta H] ;
k1=hpt(gt_dau(ii,1),gt_dau(ii,2),gt_dau(ii,3),gt_dau(ii,4),gt_dau(ii,5));
value of returned k1:
-0.000158173208030319 -0.000121964317063585 0 0 0
the third component is not right, not 0 but -0.000121965, so i wonder what i am doing wrong here?
  2 commentaires
Jan
Jan le 26 Oct 2021
We cannot run your code. Global variables are a shot in the knee of the programmer, so avoid them strictly. They are impeding the debugging of code massively.
Use the debugger to step through your code line by line. Then you will find out, why the value differ from your expectations.
Remember: All we see here is code, which we cannot run due to the missing input values. Even if the values are defined, we do not know, why you expect anything else.
tuan nguyen minh
tuan nguyen minh le 28 Oct 2021
Sorry, i do the calculation again and found out that matlab calculates right and I'm wrong. Thanks for your attention

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by