Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: matlab novice
Replies: 12   Last Post: Aug 1, 2013 7:42 AM

 Messages: [ Previous | Next ]
 Torsten Hennig Posts: 2,419 Registered: 12/6/04
Re: matlab novice
Posted: Aug 1, 2013 7:18 AM

> i get message
>
> ??? In an assignment A(I) = B, the number of
> elements in B and
> I must be the same.
>
> Error in ==> pH_Calculation_3 at 42
> pH(i) = -log10(Hplus);
>
>
> Kw = 1e-14;
> Ka = 1.755388e-5;
> pKa = 4.756;
> %
> Ca = 0.5;
> Cb = 0.1;
> Va = 100;
> Vb = 0:0.1:1500;
> %
> % This simulates initial molarity of CH3CO2H.
> Ma = (Ca * Va) / 1000;
> % This simulates initial molarity of NaOH.
> Mb = (Cb * Vb) ./ 1000;
> for i = 1:length(Mb)
> M_excess = Ma - Mb(i);
> if M_excess > 0
> Ma_final = (M_excess * 1000) ./ (Va + Vb);
> Mb_final = (Mb(i) * 1000) ./ (Va + Vb);
> Hplus = Ka * (Ma_final ./ Mb_final);
> else
> OH = (M_excess * 1000 * (-1)) ./ (Va + Vb);
> Hplus = Kw ./ OH;
> end
> pH(i) = -log10(Hplus);
> end

Try this:

Kw = 1e-14;
Ka = 1.755388e-5;
pKa = 4.756;
%
Ca = 0.5;
Cb = 0.1;
Va = 100;
Vb = 0:0.1:1500;
%
% This simulates initial molarity of CH3CO2H.
Ma = (Ca * Va) / 1000;
% This simulates initial molarity of NaOH.
Mb = (Cb * Vb) / 1000;
for i = 1:length(Mb)
M_excess = Ma - Mb(i);
if M_excess > 0
Ma_final = (M_excess * 1000) / (Va + Vb(i));
Mb_final = (Mb(i) * 1000) / (Va + Vb(i));
Hplus = Ka * (Ma_final / Mb_final);
else
OH = (M_excess * 1000 * (-1)) / (Va + Vb(i));
Hplus = Kw / OH;
end
pH(i) = -log10(Hplus);
end

Best wishes
Torsten.

Date Subject Author
8/1/13 harley
8/1/13 Torsten Hennig
8/1/13 harley
8/1/13 harley
8/1/13 Torsten Hennig
8/1/13 harley
8/1/13 harley
8/1/13 harley
8/1/13 Torsten Hennig
8/1/13 harley
8/1/13 Torsten Hennig
8/1/13 harley
8/1/13 harley