Getting the wrong output value when running the code

1 visualizzazione (ultimi 30 giorni)
Is anyone able to help me locate why my code is showing the wrong answer when it does the equation. I have the code working perfectly as I wanted it to but when running the code I get answers that are not even correct. Any way to fix this?
Thank you.
t_i='';
t_f='';
t_i = input(strcat(t_i, ' Initial Temperature: \n'));
t_f = input(strcat(t_f, ' Final Temperature: \n'));
T=t_i:2:t_f; %Range of temp. from input value
T=T+273.15; %Conversion of celsius to kelvins
fprintf('Pressure\tTemperature\n'); %to print table in command window
for t=1:length(T)
p = b-(a*0.05333/T(t)); %vapor pressure equation
p = 10.0^p;
fprintf('%f\t%f\n',p,T(t));
end
%output
% Pressure Temperature
% 19.517961 273.150000
% 21.823778 275.150000
% 24.362704 277.150000
% 27.154148 279.150000
% 30.218758 281.150000
% 33.578477 283.150000
% 37.256592 285.150000
% 41.277788 287.150000
% 45.668205 289.150000
% 50.455482 291.150000
% 55.668823 293.150000
% 61.339041 295.150000
% 67.498616 297.150000
% 74.181750 299.150000
% 81.424420 301.150000
% 89.264431 303.150000
% 97.741473 305.150000
% 106.897169 307.150000
% 116.775136 309.150000
% 127.421028 311.150000
% 138.882599 313.150000
% 151.209747 315.150000

Risposta accettata

Yongjian Feng
Yongjian Feng il 6 Lug 2021
It is a simple function here. This kind of error can be easily found using matlab debugger. Set a break point in the loop, and hand compute the value. Then compare it with what matlab gets.
  2 Commenti
Glenti Jalli
Glenti Jalli il 6 Lug 2021
using the debugger it continues to give me the same values as I get when the full code is being run. Is there some sort of inverse function (for Log of 10) built in the system that I can use?
Yongjian Feng
Yongjian Feng il 6 Lug 2021
Modificato: Yongjian Feng il 6 Lug 2021
I am not very familar with vapor pressure equattion. What are the values of a and b please?
As for the inverse function, are you looking for log10? Try log10(p) for your case.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by