How do I fix my display of the x and y values? They should be x = 1.15 and y = 3.85.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
MyKah Smith
am 27 Apr. 2021
Beantwortet: Image Analyst
am 27 Apr. 2021
%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 Kommentare
Akzeptierte Antwort
Image Analyst
am 27 Apr. 2021
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 Kommentare
Weitere Antworten (1)
Chad Greene
am 27 Apr. 2021
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 Kommentare
Siehe auch
Kategorien
Mehr zu Renewables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!