num2str error or integer error
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
%% Script
clear; clc;
E = 70*10^9
G = 30*10^9
L = 1
answer = questdlg('Would you like to find the Optimized beam and dimensions','Beam Optimizer','Yes','No','No');
switch answer
case 'Yes'
data = 1
[h b PCritval] = optimize(data,E,G,L)
plotBeam(h,b,data)
FinalCritcalval = PCritval
count = 1;
data = 2
[h b PCritval] = optimize(data,E,G,L)
plotBeam(h,b,data)
if PCritval > FinalCritcalval
FinalCritcalval = PCritval
count = 2;
end
data =3
[h b PCritval] = optimize(data,E,G,L)
plotBeam(h,b,data)
if PCritval > FinalCritcalval
FinalCritcalval = PCritval
count = 3;
end
case 'No'
fprintf('You Chose to not Optimized the beams')
end
if count == 1
fprintf('The I-Beam is optimized to have the hieghest critical load of %f',FinalCritcalval)
else if count == 2
fprintf('The Z-Beam is optimized to have the hieghest critical load of %f',FinalCritcalval)
else
fprintf('The C-Beam is optimized to have the hieghest critical load of %f',FinalCritcalval)
end
end
%% Functions
%%Ibeam function
function [A,Ixx,Iyy,Xs,Ys,J,C_w,I0] = Ibeam(t,h,b)
Cy = h/2;
Cx = b/2;
Ixx = 2*((b*t^3/12)+(t*b*((h/2)+(t/2))^2))+(t*((h))^3/12);
Iyy = 2*(t*b^3/12)+((h*t^3/12));
I0 = Ixx + Iyy;
J = (2*b*t^3+h*t^3)/3;
C_w = t*h^2*b^3/24;
A = 2*(b*t)+((h)*t);
Xs = 0;
Ys = 0;
end
%%Zbeam function
function [A,Ixx,Iyy,Xs,Ys,J,C_w,I0] = Zbeam(t,h,b)
Cy = h/2;
Cx = b/2;
Ixx = 2*((b*t^3/12)+(t*b*((h/2)+(t/2))^2))+(t*((h))^3/12);
Iyy = 2*((t*b^3/12)+(b*t*((b/2)-(t/2))^2))+((h*t^3/12));
I0 = Ixx + Iyy;
J = (2*b*t^3+h*t^3)/3;
C_w = (b^3*h^2/(12*(2*b+h)^2))*(2*t*(b^2+b*h+h^2)+(3*t*b*h));
A = 2*(b*t)+((h)*t);
Xs = 0;
Ys = 0;
end
%%Cbeam function
function [A,Ixx,Iyy,Xs,Ys,J,C_w,I0] = Cbeam(t,h,b)
h = 2*h;
A = 2*(b*t)+(h*t);
Cx = (b*t*h)/A;
Cy = h;
Ixx = (t*(h)^3/12)+(2*t*b*(h/2)^2);
Iyy = t*h*Cx^2+2*(t*b^3/12)+((2*t*b)*((b/2)-Cx)^2);
Xs = -((t*b^2*(h/2)^2/Ixx)+Cx);
Ys = 0;
I0 = Ixx + Iyy+(A*(Xs^2));
J = (t^3)*(2*b+h)/3;
C_w = (t*b^3*h^2/12)*((3*b*t+2*h*t)/(6*b*t+h*t));
end
%%Pcrit calc
function [Pcritical_matrix] = Pcrit(E,G,L,J,Iyy,Ixx,A,I0,C_w,Xs,Ys)
i = 1;
Pcritical_matrix = zeros(1,3);
Py = pi^2*E*Iyy/(L^2);
Px = pi^2*E*Ixx/(L^2);
P_alpha = (A /I0)*(G*J+(E*C_w*pi^2/L^2));
if Xs == 0 && Ys == 0
Pcr1 = Px;
Pcr2 = Py;
Pcr3 = P_alpha;
Pcritical_matrix = [Pcr1 Pcr2 Pcr3];
else
syms pCr;
m = [0 (pCr-Px) (pCr*.076);(pCr-Py) 0 0; 0 (.076*pCr) (.0089*(pCr-P_alpha))];
pCrit = solve(det(m));
Pcritical_matrix = vpa(pCrit);
end
end
function [h b PCritval] = optimize(data,E,G,L)
t = .002;
A1 = 6*10^-4;
i = 1;
if data == 1
for b = .02:.001:.2
h = (6*10^-4/(t))-(2*b);
if h > 0
[A,Ixx,Iyy,Xs,Ys,J,C_w,I0] = Ibeam(t,h,b);
[Pcritical_matrix] = Pcrit(E,G,L,J,Iyy,Ixx,A,I0,C_w,Xs,Ys);
pval = min(Pcritical_matrix);
m(:,i) = [pval h b];
i = i+1;
end
end
fprintf('You chose I-beam')
else if data == 2
for b = .01:.001:.2
h = (6*10^-4/(t))-(2*b);
[A,Ixx,Iyy,Xs,Ys,J,C_w,I0] = Zbeam(t,h,b);
[Pcritical_matrix] = Pcrit(E,G,L,J,Iyy,Ixx,A,I0,C_w,Xs,Ys);
pval = min(Pcritical_matrix);
m(:,i) = [pval h b];
i = i+1;
end
fprintf('You chose Z-beam')
else
fprintf('You chose C-beam')
for b = .065:.001:.1
h = (6*10^-4/(2*t))-b;
[A,Ixx,Iyy,Xs,Ys,J,C_w,I0] = Cbeam(t,h,b);
[Pcritical_matrix] = Pcrit(E,G,L,J,Iyy,Ixx,A,I0,C_w,Xs,Ys);
pval = min(Pcritical_matrix);
m1(:,i) = [pval h b];
m = vpa(m1,5);
i = i+1;
end
end
end
[M I] = max(m(1,:));
PCritval = m(1,I);
h = m(2,I);
b = m(3,I);
end
%%Plot Function
function plotBeam(h,b,data)
t = .002
if data == 1
figure
x = [0;b;b;((b/2)+(t/2));((b/2)+(t/2));b;b;0;0;((b/2)-(t/2));((b/2)-(t/2));0;0]
y = [0;0;t;t;(t+h);(t+h);(2*t+h);(2*t+h);(t+h);(t+h);t;t;0]
plot(x,y,'LineWidth',2,'Color','r')
[t,s] = title(['Optimized I-Beam with dimmentions of'],['Web Height= ',num2str(h), 'm Base= ', num2str(b),'m'])
fprintf('Check3')
else if data == 2
figure;
x = [0;b;b;2*b;2*b;b-t;b-t;0;0]
y = [0;0;(h+t);(h+t);((2*t)+h);((2*t)+h);t;t;0]
plot(x,y,'LineWidth',1,'Color','r')
ylim ([0 b])
xlim ([0 (2*b)+.05])
[t,s] = title(['Optimized Z-Beam with dimmentions of'],['Web Height= ',num2str(h), 'm Base= ', num2str(b),'m'])
fprintf('Check3')
else
figure;
b
h
x = [0;0;b;b;t;t;b;b;0]
y = [0;(b+(2*t));(b+(2*t));(b+t);(b+t);t;t;0;0]
plot(x,y,'LineWidth',1,'Color','r')
[t,s] = title(['Optimized C-Beam with dimmentions of'],['Web Height= ',num2str(h), 'm Base= ', num2str(b),'m'])
end
end
end
I think the error has to do with the use of vpa in the third if statment of my optimize function, causing the h and b values to be non integerers, tried to also have an xlim and ylim in the plot function any help or ideas would be greatly apreciated
2 comentarios
Respuestas (1)
Ver también
Categorías
Más información sobre Database Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!