Beer's law while loop

12 visualizzazioni (ultimi 30 giorni)
Heeho Kang
Heeho Kang il 8 Nov 2016
Risposto: Star Strider il 8 Nov 2016
L=1; %cm
e=117000; %extinction coefficient
m=1; %mass of dye to be used in mg
w=407.99; % molar weight of dye in mg/mmol
v=100; %volume of ccl4 in ml
c=m/(v*w); %molarity mmol/ml
t=logspace(1,10000,10000);
i=0;
A=0;
while A<1
A=e*L*d;
i=i+1;
d=c./t(i);
end
if A>1
disp('too concentrated')
else ('ok to use')
end
here's my code for beer's law equation. Beer's law is A=elc. e and l does not change. concentration(c) can change but since 1mg is almost impossible to measure with scale, I'm going to use serial dilution. I used the while loop for serial dilution of 10 to get the how many dilution I need to perform in order to get A<1. But somehow it says everything is 0.
Thank you for reading my question

Risposta accettata

Star Strider
Star Strider il 8 Nov 2016
I find it difficult to follow your Beer’s law implementation.
That aside, your problem is likely here:
t=logspace(1,10000,10000);
Please see the documentation for the logspace function. You are asking it to create a vector from 10^1 to 10^10000. Only the first 308 elements of your vector are finite.
The solution is to decrement ‘t’ using the linspace function:
L=1; %cm
e=117000; %extinction coefficient
m=1; %mass of dye to be used in mg
w=407.99; % molar weight of dye in mg/mmol
v=100; %volume of ccl4 in ml
c=m/(v*w); %molarity mmol/ml
t=linspace(10,1,250);
i=0;
A=0;
d = 0;
Adt = [];
while A < 1
A=e*L*d;
i=i+1;
d=c./t(i);
Adt = [Adt; A d t(i)];
end
Result = Adt(end-1:end, :)
Result =
0.9959 8.6202e-06 2.8434
1.0086 8.7312e-06 2.8072
I’m not quite sure what output you want. This records ‘A’, ‘d’, and ‘t’, and prints them for the last two steps.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by