Question

why will my function not run in the main code

##This is the main code##

%% Problem IV %%
% ON SEPARATE M FILE
ellipsoid_volume(8,17,"Volume versus depth for an ellipsoid")

## This is the function code##

% This program calls the following user-written functions
% 1. ellipsoid_volume   
% Problem 1 - Calculate volume of ellipsoid shaped tank.
figure(1)
ellipsoid_volume(3,12,'Volume versus depth for an ellipsoid')
function ellipsoid_volume(a,b,plot_title,units)
%volume of horizontal ellipsoid
%inputs:
%a - vertical semi-axis
%b - horizontal radius
%plot_title - string holding plot title
%units - optional string describing units, default = 'm'

if(nargin==3)
units='m';
end

h=linspace(0,a);

V=pi/3*(3*a-h).*(b*h/a).^2

plot(h,V)
grid on

title(plot_title);

xlabel(['Height(',units,')']);
ylabel(['Volume(',units,'^3)']);
end

Please help. See error attached.

*Problem IV 8% $ ON SEPARATE M FILE ellipsoid_volume (8,17, Volume versus depth for an ellipsoid)

Channel 6 Velocity = 1.9261m/s Error: File: ellipsoid volume.m Line: 14 Column: 12 Function with duplicate name ellipsoid_vo

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

Brother the error is basically due to the fact your function file name ellipsoid_volume.m does not contain only function. So,

Firstly copy only the below bold part to file name ellipsoid_volume.m and then run the separate file function. Also, alternatively you can copy whole below code in a script and run it. It will run.

clc
clear all
close all
figure(1)
ellipsoid_volume(3,12,'Volume versus depth for an ellipsoid')
function ellipsoid_volume(a,b,plot_title,units)
%volume of horizontal ellipsoid
%inputs:
%a - vertical semi-axis
%b - horizontal radius
%plot_title - string holding plot title
%units - optional string describing units, default = 'm'

if(nargin==3)
units='m';
end

h=linspace(0,a);

V=pi/3*(3*a-h).*(b*h/a).^2;

plot(h,V)
grid on

title(plot_title);

xlabel(['Height(',units,')']);
ylabel(['Volume(',units,'^3)']);
end


- 5 x A MATLAB R2018 HOME PLOTS APPS EDITOR PUBLISH E A Search Documentation AS - Pradeep 0 x E L Save Figure 1 Eile Edit Vie

Add a comment
Know the answer?
Add Answer to:
why will my function not run in the main code ##This is the main code## %%...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1 st s2, y(1)1 The exact solution is given by yo) - = . 1+Int Write a MATLAB code to approximate ...

    1 st s2, y(1)1 The exact solution is given by yo) - = . 1+Int Write a MATLAB code to approximate the solution of the IVP using Midpoint (RK2) and Modified Euler methods when h [0.5 0.1 0.0s 0.01 0.005 0.001]. A) Find the vector w mid and w mod that approximates the solution of the IVP for different values of h. B) Plot the step-size h versus the relative error of both in the same figure using the LOGLOG...

  • modify this code is ready % Use ODE45 to solve Example 4.4.3, page 205, Palm 3rd...

    modify this code is ready % Use ODE45 to solve Example 4.4.3, page 205, Palm 3rd edition % Spring Mass Damper system with initial displacement function SolveODEs() clf %clear any existing plots % Time range Initial Conditions [t,y] = ode45( @deriv, [0,2], [1,0] ); % tvals yvals color and style plot( t, y(:,1), 'blue'); title('Spring Mass Damper with initial displacement'); xlabel('Time - s'); ylabel('Position - ft'); pause % hit enter to go to the next plot plot( t, y(:,2), 'blue--');...

  • C++ code please asap QUESTIONS Write the test main function as described next. This function is...

    C++ code please asap QUESTIONS Write the test main function as described next. This function is NOT a member function of either of the two classes above. It is located in separate source file. Create an array of type Flight and size 10 1. Prompt the user to enter values for speed, name, and id for all 10 objects. You must use the overloaded input stream operator of class Flight. 1. Write the value of the name variable of all...

  • please help me with this MATLAB CODE and explain to me what each line does and...

    please help me with this MATLAB CODE and explain to me what each line does and what is used for? leave your comments as words, not as pictures. ..................................................................................................................................................................... clear all; close all; % For a script file, you better start with clear all and close all                        % However, for a fucntion, you better NOT to start                        % with them %% End of cell mode example %% Plot function t = 0:0.1:5; x1 = sin(2*5*t); x2 = cos(3*7*t);...

  • Consider the following function://To compile this code by itself, naturally you need a main method. #include...

    Consider the following function://To compile this code by itself, naturally you need a main method. #include <stdio.h> #include <sys/stat.h> void printFileIndexNumber(char *path){ struct stat statbuf; if (stat(path, &statbuf) == -1) perror("Failed to get file status"); else printf("%s inode number is %d", path, &statbuf.st_ino);} It uses the stat system call to get information about the file indicated by the parameter *path. It puts the information about the file in the structure struct stat statbuf and prints out the file index number/inode...

  • Please edit my following JAVA code so that there is no main function. I would like...

    Please edit my following JAVA code so that there is no main function. I would like one function in this class that completes what the current program is trying to do so that I can call this class in my main class which will be separate. import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class enterwklyincme { private static DecimalFormat df = new DecimalFormat("0.00"); public static float readFloat(Scanner reader) { float num; while (true) { try { num = Float.parseFloat(reader.nextLine()); return...

  • Creating a calculator for my CS1 class and my code was able to run but it...

    Creating a calculator for my CS1 class and my code was able to run but it crashes near the end. As far as I know, the error means that it's retrieving "null" from the variable but I haven't seen that kind of error from this kind of situation. I would appreciate any help. I'm just starting up in Java so I apologize if this is a silly question. Thank you! ``` ----jGRASP exec: java CS1Calculator ------------ Welcome to the CS1...

  • I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear...

    I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear all; format long; f=@(t,y)y*(1-y); y(1)=0.01; %%%% Exact solution [t1 y1]=ode45(f,[0 9],y(1)); figure; plot(t1,y1,'*'); hold on % Eular therom M=[32 64 128]; T=9; fprintf(' M Max error \n' ); for n=1:length(M) k=T/M(n); t=0:k:T; for h=1:length(t)-1 y(h+1)=y(h)+k*f(t(h),y(h)); end plot(t,y); hold on %%%...

  • Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read...

    Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...

  • What is wrong with my code? Why is it in infinite loop? this is the file...

    What is wrong with my code? Why is it in infinite loop? this is the file which it is reading, the code, and the infinite loop execution. Lab01-SalesReceipts-Microsoft Visual Studio File Edit View Project Build Debug Team Tools Test Analyze Window Help Debug x86 Local Windows Debugger - Lab01-SalesReceipts.cpp Lab01-SalesReceipts - (Global Scope) / Laben salesreceipts.cpp: Defines the entry point for the console application. 2 Samuel Gonzalez Checa R-include "5tda#x"h" include "1onanip 6 tinclude "iostrean include "fstream" 8 winclude "string...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT