I have developed the the simplified equation which needs to be solved to find th
ID: 2258272 • Letter: I
Question
I have developed the the simplified equation which needs to be solved to find the height which is 1/4 * pS(3r*h^2-h^3)/(r^3 * p0) = 0 where h is the height
I am stuck on how to write a matlab function to solve this equation. Please provide the code and the graphs for the question.Cannot use internal matlab functions to solve this. If you test with values provided H should equal 120.
A solid sphere of radius r and density ps is placed in a fluid of density po. The sphere sinks to a depth ofh. The volume of sphere below the fluid surface is r(arh^-h . Develop a MATLAB function to calculate h based on input values r, ps and pd Your function should prompt a user to input r, p, and po and print the output as "The sphere depth below the fluid surface is:". Test your code with r-40mm, ,-0.6 g/m1m3 and (,-1.0 gmm3. Next, develop a function that calculates the ratio h/r for a given (p/po) ratio. Plot the graph ofh/r vs. (p/ po).Explanation / Answer
Matlab code
1) To calculate h
prompt = 'enter r ';
r = input(prompt);
prompt = 'enter rhos ';
rhos = input(prompt);
prompt = 'enter rhonot ';
rhonot = input(prompt);
a=1;
b=-3*r;
c=0;
d=4*r^3*rhos/rhonot;
p=[a,b,c,d];
h=roots(p);
h
2)To calculate ratio h/r
prompt = 'enter rho ratio ';
rhoratio = input(prompt);
a=1;
b=-3;
c=0;
d=4*rhoratio;
p=[a,b,c,d];
hrratio=roots(p);
hrratio
3)to plot the required graph
for k=1:100
rhoratio=k*0.1;
a=1;
b=-3;
c=0;
d=4*rhoratio;
p=[a,b,c,d]
hrratio=max(roots(p));
matrx=zeros(1,100);
matrx(1,k)=rhoratio;
matry=zeros(1,100);
matry(1,k)=hrratio;
end
plot(matrx,matry)
The graph is a straight line.