How do I fix my display of the x and y values? They should be x = 1.15 and y = 3.85.
조회 수: 1 (최근 30일)
이전 댓글 표시
%code to calculate volume of water in a cylinder tank
voltage = 1.15; %input voltage from floater when tank is empty
%maximum voltage is 5V
%tank dimensions in metres
A = 2.63;
B = 3.945;
C = 5.9175;
x = minimum_voltage == acosd(B/2*A)*5/180;
y = maximum_voltage == ((180 - angle)/180)*5;
disp(x)
disp(y)
%Convert voltage to angle
angle = (voltage*180)/5;
disp(angle)
%Check input voltage is valid
if voltage < minimum_voltage
disp('ERROR')
elseif voltage > maximum_voltage
disp('ERROR')
volume = 'ERROR';
else
disp('Voltage seems sensible')
end
>> VolumeCalculations
1
0
41.4000
Voltage seems sensible
댓글 수: 0
채택된 답변
Image Analyst
2021년 4월 27일
Since you have not yet defined minimum_voltage and maximum_voltage, these lines will throw an error saying they are not defined. And if you had defined them, x and y would be either true or false since x and y are both set equal to a comparison condition.
x = minimum_voltage == acosd(B/2*A)*5/180;
y = maximum_voltage == ((180 - angle)/180)*5;
Simply delete all references to x and y and have this:
minimum_voltage = acosd(B/2*A)*5/180;
maximum_voltage = ((180 - angle)/180)*5;
fprintf('Min voltage = %f. Max voltage = %f.\n', minimum_voltage, maximum_voltage);
댓글 수: 0
추가 답변 (1개)
Chad Greene
2021년 4월 27일
The double equals is defining x and y as a boolean. It's saying x = 1 if minimum_voltage equals acosd(B/2*A)*5/180. Let's find out what acosd(B/2*A)*5/180 actually equals:
voltage = 1.15;
A = 2.63;
B = 3.945;
C = 5.9175;
acosd(B/2*A)*5/180
The way you have written your code, it says x = 1 if minimum_voltage equals 0.0000 + 3.7083i. Otherwise, x = 0. If you want x to be 1.15, write
x = 1.15;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Renewables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!