error in Modal Analysis code from MATLAB

2 views (last 30 days)
Panfilo Armas
Panfilo Armas on 6 May 2023
Answered: Manoj Mirge on 17 May 2023
Hi everyone,
I found this MATLAB code in their directory to help me get the frequencies and modes of a MDOF structure. I've inputted all my values into the function but it gives me an error for NM and get an error that says local function must be different than script name. Has anyone used this script before and I'm not sure what I'm doing wrong. Below is the code I'm using:
%% Newmark Function; NM
clear all
clc
load('SineSweep.mat')
g=386.4;
M=[4.3 0 0;0 4.3 0; 0 0 4.3];
K=[4494.6375 -2247.32 0;-2247.32 4494.6375 -2247.32; 0 -2247.32 2247.32];
F=g*M;
ft=AccTopFSW*g;
zet=0;
[phi,omega2]=eig(K,M);
function [disp,EF]=NM(n,nom,dt,F,ft,M,K,zet,omega2,phi)
%% By Newmark Linear Method
Mn=phi'*M*phi;
Kn=phi'*K*phi;
Ln=zeros(nom);
for i=1:nom
Ln(i,i)=(phi(:,i))'*F/Mn(i,i); % Load Contribution Facor
end
u=zeros(length(ft),nom);
v=zeros(length(ft),nom);
ac=zeros(length(ft),nom);
ft(end+1)=0;
for j=1:nom % equation of motion(Newmark linear method)
m=Mn(j,j);
k=Kn(j,j);
c=2*m*(omega2(j,j))^.5*zet/100;
K=k+3*c/dt+6*m/(dt)^2;
a=6*m/dt+3*c;
b=3*m+dt*c/2;
for i=1:length(u)-1
u(1,j)=0; %initial conditions
v(1,j)=0;
ac(1,j)=0;
df=Ln(j,j)*Mn(j,j)*(ft(i+1)-ft(i))+a*v(i,j)+b*ac(i,j); % delta Force
du=df/K;
dv=3*du/dt-3*v(i,j)-dt*ac(i,j)/2;
dac=6*(du-dt*v(i,j))/(dt)^2-3*ac(i,j);
u(i+1,j)=u(i,j)+du;
v(i+1,j)=v(i,j)+dv;
ac(i+1,j)=ac(i,j)+dac;
end
end
ft(end)=[];
%% Combine Modes Then Develop Story Responses
disp=zeros(size(u,1),n); % Story displacement
acc=zeros(size(ac,1),n); % story acceleration
EF=zeros(size(u,1),n); % Story force
for st=1:n % st is story
for j=1:nom % j is mode
disp2=zeros(size(u,1),n);
accel=zeros(size(ac,1),n);
EF1=zeros(size(u,1),n);
disp2(:,st)=phi(st,j)*u(:,j); % Chopra, pp 438; Disp=phi*U
accel(:,st)=phi(st,j)*ac(:,j);
EF1(:,st)=omega2(j,j)*M(st,st)*phi(st,j)*u(:,j); % Chopra, pp 438
disp=disp2+disp; % Displacement of Stories
acc=accel+acc; % Acceleration of Stories
EF=EF1+EF; % Seismic Force of Stories
end
end
end
I'm loading a Sinesweep acceleration data and I;ve inputted most of the values. n=3, nom=3, dt=0.002.
Please and Thank you.

Answers (1)

Manoj Mirge
Manoj Mirge on 17 May 2023
In MATLAB scripts the names of local functions and name of script in which local functions are defined must be different. If you have script named “main.mlx then you cannot define local function named “main” in that script.
It seems like you have script named “NM” and you have defined local function named “NM” in that script and that is causing the error.
You can either change the function name or script name depending upon the use case.
You can read more about local function in below attached link:

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!