% Thermocouple Example

clc             % clear the command window
clear           % clear all variables
close all       % close any existing windows
format compact	% prevent extra blank lines in the output

% Type J coefficients
c(1) = -0.0488683;
c(2) = 19873.1;
c(3) = -218615;
c(4) = 1.15692*10^7;
c(5) = -2.64918*10^8;
c(6) = 2.01844*10^9;

% Temperature/voltage relationship
% file: thermo_temp.m
% function [T] = thermo_temp(c, V)
% % Function to calculate the temperature corresponding to a voltage
% T = 0;
% for i = 1 : length(c)
%     T = T + c(i)*V^(i-1);
% end
% end

% Solving for voltage given a temperature (10 degrees)
% function [f] = my_root_func(c, V)
% f = thermo_temp(c, V) - 10;
% end
display 'voltage corresponding to 10 degrees:'
V0 = 0;  % initial guess
V10 = fzero (@(V) my_root_func(c, V), V0)

% Test results
display 'temperature corresponding to calculated voltage:'
thermo_temp(c, V10)
