Very basic calculations returning incorrect values
이전 댓글 표시
So I'm trying to run some very, very basic equations through Matlab, and I'm getting absurd values for some reason. Here is a sample of the code I'm trying to run:
r1 = 0.1;
r2 = 0.12;
r3 = 0.14;
h1 = 0.200;
h2 = 0.240;
x = r2-r1;
A1 = pi*square(r2) ;
V1 = pi*square(r1)*h1 ;
V2 = pi*square(r2)*h2 ;
Vt = V2-V1 ;
V3 = pi*square(r3)*h2 ;
Vi = V3-V2;
However the value returned by Matlab for A1 is 3.1416, when it should be more like 0.045. The same thing happens for V1, V2, and V3. Also for some reason, the values returned for V2 and V3 are both 0.754, which is kind of odd. I'm very new to this and I'm sure I'm just making some silly mistake. Any help would be appreciated.
댓글 수: 1
or simply x.*x
채택된 답변
추가 답변 (1개)
Use x^2 instead of square(x) (square is not what you expect it to be in MATLAB).
Best wishes
Torsten.
카테고리
도움말 센터 및 File Exchange에서 Desktop에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!