Answer:
Task 1 Code :
x = input("Please enter a position between 0 and 360 inches:");
if ( x<0 )
disp("The value entered is negative, taking absolute value");
x = -1*x;
end
if(x>360)
disp("The value entered is more than 360 inches");
exit; //complete closedown
end
Task 2 Code
The function is MA3_Deflection_CourgarnetID , you have to pass an input value x and the output will be in v.
function [ v ] = MA3_Deflection_CourgarnetID( x )
if(x>120); a = (x-120); else; a = 0; end
if(x>240); b = (x-240); else; b = 0; end
v = (1/(3.9e9))*(800*x^3-(13.7e06)*x - 2.5*x^4 + 2.5*(a)^4 + 600*b^3);
end
Task 3 Code
This the complete code with the user prompt.
x = input("Please enter a position between 0 and 360 inches:");
if ( x<0 )
disp("The value entered is negative, taking absolute value");
x = -1*x;
end
if(x>360)
disp("The value entered is more than 360 inches");
exit;
end
X = 0:0.1:x
Y = 0;
for i=1:length(X)
Y(i) = MA3_Deflection_CourgarnetID(X(i));
end
plot(X,Y);
grid on;
xlabel('Position on beam [inches]');
ylabel('Deflection of beam [inches]');