I don't know why the function won't run.

3 次查看(过去 30 天)
clear all;
clc;
function n = CourseProject(d);
datas = textread('Stress_History.txt');
astress = datas(:,2); % axial stress
sstress = datas(:,3); % shear stress
Sut = 720; % Ultimate strength
Sy = 400; % yield stress
Vp = 0.3; %Poisson's Rati0
MoE = 206; %Modulus of Elasticity
roe = 7861; %Density
L = 100; %Length
NC = 0.062; %Neuber Constant
Seprime = 0.87 * Sut; % Endurance limit
Snom = 430; %Nominal Stress
Tnom = 400; %Nominal Shear
Asmin = min(astress);
Asmax = max(astress);
SSmin = min(sstress);
SSmax = max(sstress);
At = 0.25*pi*(d^2);
Bendinga = 0.246 - (3.08*(10^-3)*Sut) + (1.51*(10^-5)*(Sut^2)) - (2.67*(10^-8)*(Sut^3))
Torsiona = 0.190 - (2.51*(10^-3)*Sut) + (1.35*(10^-5)*(Sut^2)) - (2.67*(10^-8)*(Sut^3))
Kf = Asmax/Snom;
Kfs = SSmax/Tnom;
Mba = ((Asmax+Asmin)*L)/2;
Mbm = ((Asmax-Asmin)*L)/2;
Ta = (SSmax+SSmin)/2;
Tm = (SSmax-SSmin)/2;
sigmaa = (32*Mba)/(pi*d^3);
sigmam = (32*Mba)/(pi*d^3);
sigprimea = sqrt((sigmaa*Kf)^2 + 3*(Ta*Kfs)^2);
sigprimem = sqrt((sigmam*Kf)^2 + 3*(Tm*Kfs)^2);
if d<= 51
kb = 1.24*(d^-0.0107);
Se = kb*Seprime;
end
if d<51
kb = 1.51*(d^-0.157);
Se = kb * Seprime;
end
n =1/((sigprimea/Se) + (sigprimem/Sut));
n = -n; % Maximize the safety factor
end
The file is saved as CourseProject.m
  3 个评论
Liam Swift
Liam Swift 2018-5-8
I use an optimization file to call the function provided.
Liam Swift
Liam Swift 2018-5-8
The error I get is:
"Error: File: CourseProject.m Line: 4 Column: 16
Function with duplicate name "CourseProject" cannot be defined."

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2018-5-8
Remove the first two lines. The first executable line should be the function statement.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by