my array don't return the true value

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 个评论

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.
Sorry, i do the calculation again and found out that matlab calculates right and I'm wrong. Thanks for your attention

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB 的更多信息

产品

版本

R2021a

标签

Community Treasure Hunt

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

Start Hunting!

Translated by