Finding volume using quad function
8 次查看(过去 30 天)
显示 更早的评论
This is the problem I have to solve. I keep getting an error message though and can't figure out what's wrong with it.
Find the volume of revolving the area of the circle(x-6)^2 +(y-7)^2 =5 about the x-axis.
R= 7+sqrt(5-(x-6)^2)
r= 7-sqrt(5-(x-6)^2)
Volume= quad('circle',(6-sqrt(5)),(6+sqrt(5)))
function [ z ] = circle( R, r )
z= pi(R.)^2 -pi(r.)^2
end
Any help would be great! Thanks
2 个评论
Andrew Newell
2011-4-7
There are lots of errors. Are you using the MATLAB editor? Put your mouse over any red line and you'll see some specific problems.
回答(2 个)
John D'Errico
2011-4-7
You define a function called circle.
function [ z ] = circle( R, r )
R= 7+sqrt(5-(x-6)2)
r= 7-sqrt(5-(x-6)2)
z= pi(R.)2 -pi(r.)2
It has input arguments R and r. Then you try to define the variables R, r, both of which are functions of something called x. Where did x come from? Did you provide it as an input to circle? (No.) In fact, there is no need to pass in R and r into the function circle if you compute them inside the function!
Next, you don't seem to know matlab syntax. What does this mean:
(x-6)2
????? I think you wanted to square (x-6) ? If so, there IS an operator to raise a number to a power. Learn it. Use it.
At the end of circle, you try to define the output z.
z= pi(R.)2 -pi(r.)2
Again, I think you need to read the beginning matlab tutorials about basic syntax. This line has too many syntax errors in it to list.
Andrew Newell
2011-4-7
To follow up on a comment - if you are using a MATLAB editor, you should see something like this:

You will certainly have a red button on the right margin indicating errors. Mouse over the red lines and you will see details.
Also, most of John's comments still apply even after your changes - especially the one about reading some MATLAB tutorials.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!