MATLAB Find out the velocity of a free-falling bungee jumper using subfunction s
ID: 2249040 • Letter: M
Question
MATLAB
Find out the velocity of a free-falling bungee jumper using subfunction structure, which is defined as:
m=70 g, t=10 s, cd=0.30, g=9.81 m/s2
Hints: Find out the velocity using subfunction and call it from main function.
A3-2. Suppose A=[1 3 5; 2 4 6; 3 5 7], create and access ASCII file.
A3-3. Modify If.. Structure as used in exercise 3.5.1 by input and disp function. Test the code by changing the variable ‘grade’
A3-4. Write a program using for loop to compute factorial. Suppose 5!=1x2x3x4x5.
Hints: x=1;
for i=1:n
x=x*i;
A3-5. Write a program to find out positive values from the matrix below:
[m,n]=size(A);
for i=1:m
for j=1:n
if A(i,j)……….
A3-6. Calculate value of k2-50 for all integers in [-10, 10] domain but only until k2-50 becomes negative. Use while----break structure and fprintf for displaying results.
A3-1. Find out the velocity of a free-falling bungee jumper using subfunction structure, which is defined as gm m=70 g, t-10 s. cd-0.30. g-9.81 m/s? Hints: Find out the velocity using subfunction and call it from main function A3-2. Suppose A=[1 3 5: 2 4 6: 3 5 7]. create and access ASCII file A3-3. Modify If.. Structure as used in exercise 3.5.1 by input and disp function. Test the code by changing the variable 'grade' A3-4. Write a program using for loop to compute factorial. Suppose 5 1x2x3x4x5 x=1 ; for i=1:n x=x * 1 ; Hints: A3-5. Write a program to find out positive values from the matrix below: 10-3 5 A=1-5 2 8 7 4 0 Hints: [m, n]-size (A) for i=1 : m if A(i,.... A3-6. Calculate value of k2-50 for all integers in [-10, 10] domain but ----break only until k2-50 becomes negative. Use while structure and fprintf for displaying resultsExplanation / Answer
A3-4
%clear % Removes all variables from memory
%clc %Clears command window
diary fact.dat
n=input('Enter a numer:'); % Receive input from user
x=1; %intial value for multiplication purpose
for i=1:1:n % for loop to repeat number 1 to n increment by 1
x=x*i;
end
disp(x); %displays the factorial value
diary
A3-1
*Create a MatLab Script file in the name of velocity1.m and Place this code and save it.
%Find the velocity
%Main Program to call the velocity function
clear % Removes all variables from memory
clc %Clears command window
diary velocity1.dat
m=70;
t=10;
cd=0.30;
g=9.81;
%%the following 4 lines used to get input at runtime. If you want to use this comment the above 4 lines and uncomment %the below 4 lines.
%m=input('Enter the value for m:');
%t=input('Enter the value for t:');
%cd=input('Enter the value for cd:');
%g=input('Enter the value for g:');
v=funVelocity(m,t,cd,g); %Function call
%v=sqrt(((g*m)/cd))* tanh(sqrt(((g*cd)/m))*t); %%this will calculate velocity with out calling function
disp('Velocity'); % Print string "Velocity" in screen
disp(v); % Print the velocity
diary
*Create a MatLab Script file in the name of funVelocity.m and Place this code and save it.
%Function to Calculate the velocity.
%Out Argument(return value carrier) - retVelocity.
%InArgument - m1,t1,cd1,g1 -- these are temporary variables.
% Function name is identified by the file name. function name and
%File name should be same.
function retVelocity = funVelocity(m1,t1,cd1,g1)
retVelocity =sqrt(((g1*m1)/cd1))* tanh(sqrt(((g1*cd1)/m1))*t1);
end
A3-5
%Find out the positive value for the given matrix
% A - Matrix
% i for row index
% j for column index
clear % Removes all variables from memory
clc %Clears command window
diary positivevalue.dat
A=[10,-3,5;-5,2,8;4,0,-7]; % Create matrix
[m,n] = size(A); % Get row and column count
for i=1:m % Indicates Row
for j=1:n % Indicates Column
if A(i,j) > 0 % Get element of ith Row and jth Column and
% Check the value is positive or not.
disp(A(i,j)); % If positive value display in screen. else skip
end % End of If Statement
end % End of for loop which handling column index
end % End of for loop which handling row index
diary
A3-2
% Create and Access Ascii file for matrix A
diary CreAscii.dat
clear % Removes all variables from memory
clc %Clears command window
A=[1,3,5;2,4,6;3,5,7]; % Create matrix
disp(A); % Display Matrix A in Screen
%M = magic(3);
dlmwrite('MatrixFile.txt',A); %Write the Matrix in to the file named
%MatrixFile.
type('MatrixFile.txt'); % To View the file content
B=dlmread('MatrixFile.txt'); %Read the file content to the Matrix B
B=B*4; %Multiply 4 with the each element of Matrix B
disp(B); % Display Matrix A in Screen
diary
A3-6
%Calculate value of k2-50 for all integers in [-10, 10] domain
%but only until k2-50 becomes negative.
%Use while----break structure and fprintf for displaying results.
diary calIntegers.dat
clear % Removes all variables from memory
clc %Clears command window
k = -10; % Starting value
fileID = fopen('Calculated.txt','w'); %File reference store in file pointer fileID
fprintf(fileID,'%10s %s ','Integer','k2-50'); % Writes the Heading in file
while( k <= 10) % Repeat the step till it reaches max limit of domain
v=( k*k)-50; % Find k2-50 value
if ( v > 0) % Check for non negative number
fprintf(fileID,'%10d %d ',k,v); % print non negative number calculation in file
end
k=k+1; % Increments k value for next integer
end
fclose(fileID); % Close the file after completing file write
disp('File Contents are:') %To display in screen
type('Calculated.txt'); %To display file content in screen
diary
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.