Few questions in matlab assignment

3 vues (au cours des 30 derniers jours)
Choy Chak Kei
Choy Chak Kei le 1 Déc 2019
Réponse apportée : Rik le 1 Déc 2019
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])

Réponses (1)

Rik
Rik le 1 Déc 2019
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.

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by