Need Help with MATLAB Project? We’ve Got You CoveredWe, at Matlab Assignment Experts, clearly understand that getting started and perfectly tackling your Matlab project does not come easily. That’s why we are here for you; we will not only aid you with your project but also offer tutoring services t...
% ENGR2060
% Lab4
clear; clc;
% User input handling:
operation = 0; % Operation to perform
array = 0; % Array for calcuations
% Operation input:
fprintf( "Which operation do you wish to perform? \r\n");
fprintf( "(1) Arithmetic mean \r\n(2) Standard deviation \r\n(3) Harmonic mean\r\n" );
% Will loop until enter correct operation value. After error reporting, you
% can try again
while(1)
operation = input( "Insert and press Enter: " );
if((1 ~= length(operation)) || isempty(operation))
fprintf( "Operation must be scalar value. Try again \r\n" );
continue;
end
if((operation ~= 1) && (operation ~= 2) && (operation ~= 3))
fprintf("Operation value is in ragne [0 3]. Try againg:\r\n");
continue;
else
break;
end
end
input_number = 0; % Variable holds input numbers
% Insert number loop, after some errors you can try again (ex. insert array instead of scalar value)
fprintf( "Insert number one by one (-99 is terminating): \r\n" );
while( -99 ~= array( end ) )
input_number = input( "" );
if( 1 ~= length(input_number) )
fprintf( "You can insert numbers only one by one (scalar values). \r\n" );
continue;
end
array = [ array , input_number ];
end
array = array(2:end-1); % Discard terminator and initial zero
% Call calculation function
val = ASH( operation , array );
% Report result
if(1 == operation)
fprintf("Arithmetic mean is: %d \r\n" , val);
elseif(2 == operation)
fprintf("Standard deviation is: %d \r\n" , val);
elseif(3 == operation)
fprintf("Harmonic mean is: %d \r\n" , val);
else
error( "Operation value error.\r\n" );
end
function ret_val = ASH( operation , array )
%ASH Function calculates Arithmetic mean,
%standard deviation or harmonic mean
% Input:
% operation -> 1, 2 or 3 for am, sd or hm respectively
% array -> array to perform calculations
% Output:
% ret_val -> calculated value of am, sd or hm
arr_size = length(array);
% Error checking...
if(isempty(array) || 1 > arr_size)
error( "Array must contain more then one number.\r\n" );
end
if(isempty(operation) || 1 ~= length(operation))
error( "Operation must be singe value.\r\n" );
end
if((3 < operation) ||(1 > operation))
error( "Operation range is [1 3]\r\n" );
end
% Calculations:
sumX = 0;
tmp = 0;
if(1 == operation)
sumX = log(prod(exp(array)));
ret_val = sumX/arr_size;
elseif(2 == operation)
sumX = log(prod(exp(array)));
meanX = sumX/arr_size;
ret_val = sqrt(log(prod(exp((array - meanX).^2)))/(arr_size - 1));
elseif(3 == operation)
sumX = log(prod(exp(1./array)));
ret_val = arr_size/sumX;
else
error( "Operation value error.\r\n" );
end
end % ASH
% ENGR2060
% Lab4
clear; clc;
% User input handling:
operation = 0; % Operation to perform
array = 0; % Array for calcuations
% Operation input:
fprintf( "Which operation do you wish to perform? \r\n");
fprintf( "(1) Arithmetic mean \r\n(2) Standard deviation \r\n(3) Harmonic mean\r\n" );
% Will loop until enter correct operation value. After error reporting, you
% can try again
while(1)
operation = input( "Insert and press Enter: " );
if((1 ~= length(operation)) || isempty(operation))
fprintf( "Operation must be scalar value. Try again \r\n" );
continue;
end
if((operation ~= 1) && (operation ~= 2) && (operation ~= 3))
fprintf("Operation value is in ragne [0 3]. Try againg:\r\n");
continue;
else
break;
end
end
input_number = 0; % Variable holds input numbers
% Insert number loop, after some errors you can try again (ex. insert array instead of scalar value)
fprintf( "Insert number one by one (-99 is terminating): \r\n" );
while( -99 ~= array( end ) )
input_number = input( "" );
if( 1 ~= length(input_number) )
fprintf( "You can insert numbers only one by one (scalar values). \r\n" );
continue;
end
array = [ array , input_number ];
end
array = array(2:end-1); % Discard terminator and initial zero
% Call calculation function
val = ASH( operation , array );
% Report result
if(1 == operation)
fprintf("Arithmetic mean is: %d \r\n" , val);
elseif(2 == operation)
fprintf("Standard deviation is: %d \r\n" , val);
elseif(3 == operation)
fprintf("Harmonic mean is: %d \r\n" , val);
else
error( "Operation value error.\r\n" );
end
function ret_val = ASH( operation , array )
%ASH Function calculates Arithmetic mean,
%standard deviation or harmonic mean
% Input:
% operation -> 1, 2 or 3 for am, sd or hm respectively
% array -> array to perform calculations
% Output:
% ret_val -> calculated value of am, sd or hm
arr_size = length(array);
% Error checking...
if(isempty(array) || 1 > arr_size)
error( "Array must contain more then one number.\r\n" );
end
if(isempty(operation) || 1 ~= length(operation))
error( "Operation must be singe value.\r\n" );
end
if((3 < operation) ||(1 > operation))
error( "Operation range is [1 3]\r\n" );
end
% Calculations:
sumX = 0;
tmp = 0;
if(1 == operation)
for i = 1:arr_size
sumX = sumX + array(i);
end
ret_val = sumX/arr_size;
elseif(2 == operation)
for i = 1:arr_size
sumX = sumX + array(i);
end
meanX = sumX/arr_size;
for i = 1:arr_size
tmp = tmp + (array(i) - meanX)^2;
end
ret_val = tmp/(arr_size - 1);
elseif(3 == operation)
for i = 1:arr_size
sumX = sumX + 1/array(i);
end
ret_val = arr_size/sumX;
else
error( "Operation value error.\r\n" );
end
end % ASH
wavelegths=[0.7800 0.6949 0.6559 0.5843 0.5206 0.4914 0.4378];
freq=[440.0 493.9 523.2 587.3 659.3 698.5 784.0];
plot(wavelegths.^(-1),freq)
xlabel('Wavelength^{-1}')
ylabel('Frequency')
M=0.2;
G=9.8;
R=input("Enter Radius: ");
v=sqrt(G*R);
fprintf('\n Minimum Speed to avoid falling down is %f m/sec\n',v)
while(1)
z=input('Enter RD to convert Radians to Degrees or DR for Degress to Radians:','s');
if(strcmp(z,'RD'))
r=input('Enter angle values in Radians:');
fprintf('\nValue in Degrees:')
d=r*180/pi
elseif(strcmp(z,'DR'))
d=input('Enter angle values in Degrees:');
fprintf('\nValue in Radians:')
r=d*pi/180
elseif(isempty(z))
break;
else
fprintf('Wrong Input\n')
end
end
while(1)
n=input('Enter Name:','s');
add=input('Enter address:','s');
a=input('Enter amount of purchase: $');
z=input('Enter type of purchase(L for Laptop/D for Desktop):','s');
if(z=='L')
if(a>=0 && a<=250)
d=0;
elseif(a>250 && a<=570)
d=5;
elseif(a>500 && a<=1000)
d=7.5;
elseif(a>1000)
d=10;
else
fprintf('Wrong Amount\n')
continue
end
elseif(z=='D')
if(a>=0 && a<=250)
d=5;
elseif(a>250 && a<=570)
d=7.6;
elseif(a>500 && a<=1000)
d=10;
elseif(a>1000)
d=15;
else
fprintf('Wrong Amount\n')
continue
end
else
fprintf('\nWrong Input\n')
continue
end
final_amount=a-(a*d/100);
fprintf('\nName: %s',n)
fprintf('\nAddress: %s',add)
fprintf('\nNet Amount: $%f',final_amount)
k=input('\nDo you want to continue purchase:','s');
if(k~='y'&&k~='Y')
break;
end
end
fprintf('\nYou have exit purchase screen, goodbye\n')