Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab help 2. Use a while loop control structure and an incremental direct sear

ID: 1844204 • Letter: M

Question

Matlab help

2. Use a while loop control structure and an incremental direct search algorithm to find an approximate value for the first positive (i.e., P> 0) rootl of the equation for the maximum allowable load in an eccentrically loaded column: P ec P L Sec EI 2 Your program should be in the form of a MATLAB function m-file defined as follows: function P maxload (smax,A, e, c,r,E, I, L, deltaP) The input arguments are defined as follows (suggested values for testing are indicated in parentheses) maximum allowable stress Omax (36 ksi) area of column cross-section (9.8 in') load eccentricity (0.75 in) distance from neutral axis to extreme fiber of column (1.565 in) radius of gyration (0.9 in) Young's modulus of elasticity (29,000 ksi) moment of inertia of column cross-section (8 in') column length (96 in) smax deltaPincrement of P to be used in your search (1 kip) Name your submitted file maxload.m. You may assume that the values of all input arguments passed to your function are valid double precision real numbers (i.e., you don't have to worry about error checking the input arguments for this program) and that a positive root for the function does exist. The output value P returned by your program is defined as the midpoint of the final deltaP interval that contains the root. Within these assumptions, your program must be general in the sense that it will work for any combination of values for the input arguments. HINT: You know you have crossed the P-axis there is a sign change in f(P-i.e., when BONUS: You can earn one extra point if your program correctly generates a plot of the function that shows the first positive root.

Explanation / Answer

maxload function:

function p= maxload()

f = inline('36-((P./9.8).*(1+((0.75*1.565./(0.9.^2)).*sec((P./(29000.8)).^0.5).*(96./2))))','P');

% provide the equation you want to solve with R.H.S = 0 form.
% Write the L.H.S by using inline function
% Give initial guesses.
% Solves it by method of bisection.
% A very simple code. But may come handy
flag=0;
while flag==0
if f(a)*f(b)>0
b=b+1;
else
flag=1;
p = (a + b)/2;
err = abs(f(p));
while err > 1e-7
if f(a)*f(p)<0
b = p;
else
a = p;
end
p = (a + b)/2;
err = abs(f(p));
end
end

end
end

main window execution:

maxload

result:

ans =

4.9999