Few questions in matlab assignment

조회 수: 3 (최근 30일)
Choy Chak Kei
Choy Chak Kei 2019년 12월 1일
답변: Rik 2019년 12월 1일
I am sorry to bother that I am a rookie in using matlab. I can't even run the function. What should be fixed? Please give a help.
Write a MATLAB function named “cone” to accept inputs r and h, and return output V, where r, h, and V are respectively the radius, height, and volume of a cone.
function[V] = cone ( r, h )
cone=(1/3)*h*pi*(r^2);
end.
Edit by Rik (moved from 'answer'):
The second question is:
Write a MATLABscriptto generate data and plot the function y = 1/xas shown below. The plot is in greencolourwith diamondmarkers.
123.jpeg
but i can only get this graph by this script:
octave-online-line-5.png
x=linspace(-10,10,20)
y=1./x;
plot(x,y,'gd')
ylim([-1 1])

답변 (1개)

Rik
Rik 2019년 12월 1일
If you paste your code in the Matlab editor you will see two mlint warnings and one error.
The first warning is that V is not defined in your function, the second warning is that the variable cone is unused. You should not use the name of the function as a variable, so if you replace cone by V that should solve your issue.
The error can be solved by removing the point after end.
function V = cone ( r, h )
V=(1/3)*h*pi*(r^2);
end.
As for your second question: your code should result in the upper image. The file name suggests that you are using Octave instead of Matlab. Because this is a Matlab forum, usually only questions will be answered where the issue can be reproduced in Matlab.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by