How can I find my X value given my Y value

20 visualizaciones (últimos 30 días)
Brittany Isbister
Brittany Isbister el 23 de En. de 2021
Editada: Athrey Ranjith Krishnanunni el 23 de En. de 2021
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 comentario
CMdC
CMdC el 23 de En. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Athrey Ranjith Krishnanunni
Athrey Ranjith Krishnanunni el 23 de En. de 2021
Editada: Athrey Ranjith Krishnanunni el 23 de En. de 2021
There are two major bugs here:
  1. Incorrect function declaration syntax, as @CMdeCarli has pointed out, and
  2. 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.

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by