Why is MatLab outputting 0s instead of the value?
1 次查看(过去 30 天)
显示 更早的评论
I am trying to create a matrix of an equation, E2, evaluated at different values of x (in a matrix). Why is it outputting 0s in the E2 matrix, but when I evaluate the equation at a certain element of the x matrix individually, it can print it just fine?
>> format long
>> x
x =
0.100000000000000
0.010000000000000
0.001000000000000
0.000100000000000
0.000010000000000
0.000001000000000
0.000000100000000
0.000000010000000
0.000000001000000
0.000000000100000
0.000000000010000
0.000000000001000
0.000000000000100
0.000000000000010
>> E2 = (-1/(1+sec(x)))'
% here it seems that E2 is only printing first element of x array
E2 =
-0.498747913711429
0
0
0
0
0
0
0
0
0
0
0
0
0
% however, when I evaluate at different elements of the matrix seperately,
% it can print it... see...
>> E2 = (-1/(1+sec(x(2))))'
E2 =
-0.499987499791664
>> E2 = (-1/(1+sec(x(7))))'
E2 =
-0.499999999999999
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!