User defined function for volume of a fuel tank
이전 댓글 표시
Write a user-defined function (for the function name and argument, use V= Volfuel(y)) that gives the volume f fuel in the tank (in gallons) as a function of the height y (measured from the bottom). use the function to make a plot of the volume as a function of h for 0<=h<=40 in.
I have no clue where to even start on this problem. Any help would be awesome
댓글 수: 4
Jan
2015년 4월 12일
Please explain, what you have done so far: Are you able to start Matlab and open an editor window? Did you read the documentation concerning "functions"? The Getting Started chapters are thought for beginners, especially when they do not have any clue yet.
john barnes
2015년 4월 13일
john barnes
2015년 4월 13일
답변 (2개)
Chad Greene
2015년 4월 12일
0 개 추천
Where to start? The same way you'd solve the problem on paper. Actually, it's probably a good idea to solve the problem on paper before writing any code. I've found that getting equations into simplest form on paper makes the equations easy to code, easy to troubleshoot typos, and simple equations make for efficient computing.
On your paper and on your computer screen, you'll probably start with the knowns, then there will be some math, then a plot.
Star Strider
2015년 4월 13일
0 개 추천
Start with the shape of the tank. Is it a cylinder, sphere, or something else? If a cylinder for instance, is its long axis oriented vertically or horizontally? It’s essentially geometry from there.
The ‘user-defined function’ is a function you write to your specifications to do what you want it to do. See Function Basics for how functions work in MATLAB, and how to write them and use them.
댓글 수: 4
john barnes
2015년 4월 13일
Chad Greene
2015년 4월 13일
Sounds like your user function might be able to start with
function [] = myfunction(bottomRadius,height)
topRadius = 1.5*bottomRadius;
% some math here
% some plotting here
end
It'll be a file of its own that you'll call myfunction.m. Then users will be able to simply type
myfunction(5,3)
to plot a cone of bottom radius = 5, height = 3.
john barnes
2015년 4월 13일
Chad Greene
2015년 4월 13일
Anything inside those brackets is an output of the function. I left it empty, because I don't know exactly what you want as output. Here's an example of a function that lets a user enter any radius and color of a circle. It calculates the area of the circle and plots the circle using the circles function.
The output h is simply a handle for the plotted graphics object(s). It's not necessary to include h, but it gives users the ability to tinker with properties after plotting.
function [area,h] = circlearea(radius,color)
% math:
area = pi*radius.^2;
% make a plot:
h = circles(1,1,radius,'facecolor',color);
end
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!