Hi Kreil,
Would you be so kind as to help dispel a few minor doubts I am having regarding the code in the following instances:
1) v = r*cos(alpha)*[1 + (r*sin(alpha))/(l*sin(beta))] and alpha changes from 0 to 2pi.
I hence wrote:
alpha = 0:pi/10:2*pi;
v = r*cos(alpha).*(1 + (r*sin(alpha))./(l*sin(beta)));
Should alpha indeed be treated as a vector whilst defining v (I am referring to the use of the dot operations)?
2) Using function rand, should a matrix of random integers in the interval [55..100] be generated thus:
M = ceil((rand(5,5)+(11/9))*45);?
3) Should six concentric circles whose radii vary between 0.5 and 1.75 (with intervals of 0.25) be plotted thus:
theta = linspace(0, 2*pi, 50);
[X, Y] = meshgrid(0.5:0.25:1.75, theta);
plot(a+cos(Y).*X, b+sin(Y).*X);?
4) May I plot what is called a Mobius Strip, whose equation is
x = s*cos(t/2)*cos(t) + cos(t); y = s*cos(t/2)*sin(t) + sin(t); z = s*sin(t/2), where -0.4<=s<=0.4 and 0<=t<=2pi, thus:
s = -0.4: 0.05: 0.4;
t = 0: pi/50: 2*pi;
[X, Y] = meshgrid(s, t);
surf(X.*cos(Y/2).*cos(Y) + cos(Y), X.*cos(Y./2).*sin(Y) + sin(Y), X.*sin(Y./2));?
5) A swimmer is trying to cross a river 1.1 km wide. The velocity of the swimmer is given as 0.95 km/h in the vertical direction, whilst that of the stream is S = 1.3 km/h in the horizontal direction. I am asked for the swimmer's velocity relative to the ground ("true-velocity" vector T) and the speed. May I implement that thus:
AB = 1.1;
V = [0 0.95];
S = [-1.3 0];
T = V + S;
magnitude = norm(T);?
6) I'd like to write a function which calculates the pressure drop given by: P = (1/2)*rho*omega^2*(L/D)*lambda
where rho - fluid's density, omega - fluid's velocity, L - pipe's length, D - pipe's diameter, lambda - function of the Reynolds number.
* For Reynolds<2320, lambda = 64/Reynolds
* For 2320<Reynolds<10^5, lambda = 0.3164/(Reynolds^0.25)
* For 10^5<Reynolds<10^6, 1/sqrt(lambda) = 2lg(Reynolds*sqrt(lambda)) - 0.8, which is to be solved via iteration following this algorithm: letting tol = 0.01 and lambda0 = 1, the starting value x0 should be x0 = 1/sqrt(lambda0) whereas the next value is x = 2lg(Reynolds/x0) - 0.8.
* For Reynolds>10^6, calculations are halted and the program generates a message about that using the error() function.
May I code it thus:
function PDROP = ex(rho, omega, length, diameter, Reynolds)
if (Reynolds<2320)
lambda = 64/Reynolds;
elseif (Reynolds>2320 && Reynolds<10^5)
lambda = 0.3164/(Reynolds^0.25);
elseif (Reynolds>10^5 && Reynolds<10^6)
tol = 0.01;
x0 = 1;
x = 2*log10(Reynolds) - 0.8;
while (abs(x - x0) > tol)
x0 = x;
x = 2*log10(Reynolds/x0) - 0.8;
end
lambda = x^(-2);
elseif (Reynolds>10^6)
error('Reynolds number must not be larger than 10^6');
end
PDROP = 0.5*rho*(omega^2)*(length/diameter)*lambda;?