How can I find my X value given my Y value
2 views (last 30 days)
Show older comments
Hi all,
I'm not really sure what the right answer is. I've tried to use everything I know and I'm still not sure. I'm trying to get my code to output the first T value that the reaction rate value is greater than 0.1. I can find the reaction rate value, but I'm not sure how to code finding the T value after that. I'm not sure if I even coded it the right way for finding the first reactionRate value greater than 0.1. Thank you for all your help!
function[Q,R,Ko,T]=IsbisterLab11() %inputs of the function are Q,R,Ko,T
R=1.987; % cal/mol K
Q=8000;%cal/mol
Ko=1200; %min^-1
T=linspace(100,500,200); %in Kelvin
reactionRate=Ko*exp((-Q)./(R.*T)); %Given formuldisp('Table showing temperature and the corresponding reaction rate value');
x=table(T',reactionRate');% Setting up the table
x.Properties.VariableNames={'Temperature' 'Reaction Rate'};% Giving the Columns of the table names
find(0.1,1,'first')%finding the r value that is greater than 0.1
1 Comment
CMdC
on 23 Jan 2021
I think you have to put the Outputs before a functionand not the inputs. Check it.
Like Function [outputs] = IsbisterLab11 (inputs here);
Check it out I am very beginner I am not sure.
Answers (1)
Athrey Ranjith Krishnanunni
on 23 Jan 2021
Edited: Athrey Ranjith Krishnanunni
on 23 Jan 2021
There are two major bugs here:
- Incorrect function declaration syntax, as @CMdeCarli has pointed out, and
- Improper use of the find function.
To fix them, rewrite your function as the following:
function Tval = IsbisterLab11(Q, R, Ko, T) %inputs of the function are Q,R,Ko,T
reactionRate = Ko * exp(-Q./(R.*T)); % Given formula
% create table and display it
x = table(T',reactionRate'); % Setting up the table
x.Properties.VariableNames = {'Temperature', 'ReactionRate'}; % names of columns
disp('Table showing temperature and the corresponding reaction rate value');
disp(x)
% find the first index of reactionRate that is greater than 0.1
idx = find(reactionRate > 0.1, 1, 'first');
Tval = T(idx); % corresponding T value
end
and call it like this:
R = 1.987; % cal/mol K
Q = 8000; % cal/mol
Ko = 1200; % min^-1
T = linspace(100,500,200); % in Kelvin
Tval = IsbisterLab11(Q, R, Ko, T)
Your earlier variable name 'Reaction Rate' is not valid because it has a space in between.
0 Comments
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!