MATLAB Answers

error using "=" in solving equation

13 views (last 30 days)
Aires Bulik
Aires Bulik on 6 Jun 2020 at 2:56
Edited: Ameer Hamza on 6 Jun 2020 at 4:34
Hello, I'm a newbie to matlab and have few questions to ask: first of all, can you help me to check my script? It says that there is error using "=" in the equation at line 11 of the script
n=2.2;
m=1.86;
p=0.153; %p is defined as porosity
Qv=0.980;
B=3.200;
Rw=0.265;
Rt=[4.05; 4.10; 4.22; 4.30; 4.38; 4.54; 4.82; 5.03; 5.23; 5.43; 5.64; 5.80;6.24; 6.49; 6.61;6.73; 6.73; 6.69; 7.01; 7.50; 7.78; 8.15; 8.27; 8.47; 9.24; 9.97; 10.58;10.95; 11.39; 11.64; 12.00; 12.41; 13.46; 13.91; 15.20; 19.28; 21.08;22.83;24.77; 26.23; 28.06; 30.17;31.02; 31.50];
SW=[1.000; 0.998; 0.962; 0.938; 0.913; 0.895; 0.883; 0.871; 0.859; 0.840; 0.822; 0.816; 0.775; 0.763; 0.751; 0.745; 0.739; 0.721; 0.702; 0.684; 0.666; 0.654; 0.642; 0.611; 0.590; 0.563; 0.557; 0.549; 0.531; 0.519; 0.500; 0.488; 0.476; 0.458; 0.391; 0.361; 0.342; 0.324; 0.318; 0.306; 0.294; 0.288; 0.285; 0.276];
%SW is defined as Sw measured
fprintf('Water_Saturation')
(Sw^n) + (Sw^(n-1))=Rw./(B*Qv*Rw.*Rt.*(p^m));
fprintf('\n%6.4s\t%6.4s\t%6.4s\n','Rt','Sw','SW')
for i = 1: length(Rt)
fprintf('%6.4f\t%6.4f\t%6.4f\n',Rt(i),Sw(i),SW(i))
end
Also, I'm trying solve for the variable Sw as shown in the equation line 11 using the if-elseif statement but i don't know how should the string look like. Your help is highly appreciated

  0 Comments

Sign in to comment.

Answers (1)

Ameer Hamza
Ameer Hamza on 6 Jun 2020 at 4:34
Edited: Ameer Hamza on 6 Jun 2020 at 4:34
That syntax is incorrect in MATLAB. You need to use fsolve() to solve an equation numerically
n=2.2;
m=1.86;
p=0.153; %p is defined as porosity
Qv=0.980;
B=3.200;
Rw=0.265;
Rt=[4.05; 4.10; 4.22; 4.30; 4.38; 4.54; 4.82; 5.03; 5.23; 5.43; 5.64; 5.80;6.24; 6.49; 6.61;6.73; 6.73; 6.69; 7.01; 7.50; 7.78; 8.15; 8.27; 8.47; 9.24; 9.97; 10.58;10.95; 11.39; 11.64; 12.00; 12.41; 13.46; 13.91; 15.20; 19.28; 21.08;22.83;24.77; 26.23; 28.06; 30.17;31.02; 31.50];
SW=[1.000; 0.998; 0.962; 0.938; 0.913; 0.895; 0.883; 0.871; 0.859; 0.840; 0.822; 0.816; 0.775; 0.763; 0.751; 0.745; 0.739; 0.721; 0.702; 0.684; 0.666; 0.654; 0.642; 0.611; 0.590; 0.563; 0.557; 0.549; 0.531; 0.519; 0.500; 0.488; 0.476; 0.458; 0.391; 0.361; 0.342; 0.324; 0.318; 0.306; 0.294; 0.288; 0.285; 0.276];
%SW is defined as Sw measured
fprintf('Water_Saturation')
Sw = zeros(size(Rt));
for i=1:numel(Rt)
fun = @(Sw) (Sw^n)+(Sw^(n-1))-Rw./(B*Qv*Rw.*Rt(i).*(p^m));
Sw(i) = fsolve(fun, 0);
end
fprintf('\n%6.4s\t%6.4s\t%6.4s\n','Rt','Sw','SW')
for i = 1: length(Rt)
fprintf('%6.4f\t%6.4f\t%6.4f\n',Rt(i),Sw(i),SW(i))
end
Result
Rt Sw SW
4.0500 1.1613 1.0000
4.1000 1.1531 0.9980
..
..
31.0200 0.3209 0.2850
31.5000 0.3175 0.2760

  0 Comments

Sign in to comment.