funtion for surface area

조회 수: 3 (최근 30일)
Bobby
Bobby 2011년 11월 23일
s = pi^2(2r+d)d
W=yst
r=0.35in
d=0.12in
t=0.002in
y=0.696 lb/in^3
here is what I did:
function W = Weight(r,d,t,y)
%This function calculates the weight of the coating
%on an object with surface area S of a ring in the shape of a torus
S=pi^2*(2*r+d)*d;
W=y*S*t;
end
is that correct?
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 11월 23일
Homework functions that are not well commented are not correct answers.
Bobby
Bobby 2011년 11월 23일
So its not right?
Can you give me some idea what I did wrong?

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2011년 11월 23일
Please test your function with some test data until you are sure, that it works correctly.

Walter Roberson
Walter Roberson 2011년 11월 23일
In universities around here, failure to document what all the input arguments mean, results in automatic failure for the assignment, and failure to check that all the input arguments are within range results in marks being docked for the assignment.
There is absolutely nothing in your code to indicate that I could not, for example, pass in -17 for "d".
Calculating weight based upon density times surface area is mathematically invalid. Look at the units: if you are calculating an area then the unit for that would be distance-squared (e.g., inches squared, centimeters squared), but density is in weight per distance-cubed, so you would end up with weight per distance rather than the pure weight unit that you need to get out.
You appear to be attempting to get around this by multiplying surface area by "t" distance units. What is "t"? You have not documented what it means. One would suspect that "t" might stand for "thickness". If so, then unless your thickness is "negligible" compared to your inner and outer radii, working by calculating the surface area is not a sufficiently good approximation.
When you have a thickness of a shell around the outside of an object, in order to calculate the weight of that shell, you need to calculate the volume of the shell alone. The volume of the shell alone is the difference between the volume of the original object and the volume of the object extended by the thickness of the shell. Extending an object by the thickness of a shell decreases inner radii and increases outer radii.
You need a volume formula, not a surface-area formula.
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 11월 23일
As you might have observed, above, if you post homework and ask "Is it correct?", the response you get back might inform you that, "No, the formula you show is the wrong one for that purpose!"
The question "Is it correct" is very different from "Would I get full marks on this assignment if I submitted this code?" Predicting how a marker will mark particular code is not often fruitful.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by