How can I find my X value given my Y value

조회 수: 21 (최근 30일)
Brittany Isbister
Brittany Isbister 2021년 1월 23일
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
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
Athrey Ranjith Krishnanunni 2021년 1월 23일
편집: Athrey Ranjith Krishnanunni 2021년 1월 23일
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.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by