0% found this document useful (0 votes)
28 views

Answer No 2:: % Taking User Input

The document calculates the values of two integrals over a rectangle region. It first takes in user inputs to define the rectangle and a point outside the rectangle. It then numerically evaluates the integrals of 1/r and 1/r^3 over the rectangle using a Riemann sum, and displays the results.

Uploaded by

Victor Daggers
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Answer No 2:: % Taking User Input

The document calculates the values of two integrals over a rectangle region. It first takes in user inputs to define the rectangle and a point outside the rectangle. It then numerically evaluates the integrals of 1/r and 1/r^3 over the rectangle using a Riemann sum, and displays the results.

Uploaded by

Victor Daggers
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Answer No 2:

clear all
clc
% Taking user input
prompt = 'Specify L/B ratio :'
LB = input(prompt);
prompt = 'Specify L/T ratio :'
LT = input(prompt);
L=input('Enter the length of vessel:');
if (L>0)
B=L/LB;
T=L/LT;
syms x
y=(B/2)*(1-(2*x/L)^2)*(1-(2*T/T)^2);
Waterplane_area=int(y,0,L);
display("The Waterplane area for this length is");
display(Waterplane_area);
else
display("Length must always be a positive value");
end
Command Window:

Specify L/B ratio :10

Specify L/T ratio :14

Enter the length of vessel:50

>>

Output:

prompt = 'Specify L/B ratio :'


prompt = 'Specify L/T ratio :'
"The Waterplane area for this length is"
Waterplane_area =
Answer No 3:

1 x 
Calculate the value of  r ds ,  ds for the rectangle  2, 2   (1,1) where
S S
r3
P ( x, y, z )  (6,5,10)

Answer:

clear all
clc
% Taking user input
prompt = 'The farthest vertex of the rectangle [x y]:'
x3 = input(prompt);
prompt = 'Specify any point outside the rectangle [x y z]'
q = input(prompt);
x1 = [-2 -2];
x2 = [x3(1) -2];
x4 = [-2 x3(2)];
% Displaying the rectangle
rectangle('Position',[-2 -2 3 3]);

X = -2:1:x3(1);
Y = -2:1:x3(2);
display(X);
display(Y);

% Finding the answer of integral 1/r ds


I = 0;
for i = X(1) : X(x3(1))
for j = Y(1) : Y(x3(2))
C = [i+0.5 j+0.5 0];
di = sqrt((q(1)-(i+0.5))^2 + (q(2)-(j+0.5))^2 + (q(3)^2));
u = 1/di;
I = I + u;
end
end
display(I);

% Finding the answer of the next integral


W = 0;
for i = X(1) : X(x3(1))
for j = Y(1) : Y(x3(2))
C2 = [i+0.5 j+0.5 0];
ti = sqrt((q(1)-(i+0.5))^2 + (q(2)-(j+0.5))^2 + (q(3)^2));
v = 1/(ti^3);
dq = (q(1) - (i+0.5))*v;
W = W + dq;
end
end
display(W);

Output:

prompt = 'The farthest vertex of the rectangle [x y]:'


prompt = 'Specify any point outside the rectangle [x y z]'

X = 1×4
-2 -1 0 1
Y = 1×4
-2 -1 0 1
I = 0.0710
W = 0.0027

You might also like