How can I find my X value given my Y value
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
CMdC
2021-1-23
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.
回答(1 个)
Athrey Ranjith Krishnanunni
2021-1-23
编辑:Athrey Ranjith Krishnanunni
2021-1-23
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!