Error: File: centraldiff.m Line: 1 Column: 11 Unbalanced or unexpected parenthesis or bracket

1 visualización (últimos 30 días)
function[U(m+1)]=centraldiff(Tn,zeta,U(1),U(2),acc(m),dt)
%Tn=2*pi*sqrt(m/k)
%U(1)=0; % displacement at point t=0 of SDOF
%V(1)=0; % velocity at point t=0 of SDOF
%zeta=0.05;
%Tn=2.5
%U(2)=0;
for m=2:20;
U(m+1)=-acc(m)/(1/dt^2+2*pi*zeta/Tn*dt)+((-1/dt^2+2*pi*zeta/Tn*dt)/(1/dt^2+2*pi*zeta/Tn*dt))*U(m-1)+((-4*pi^2/Tn^2+2/dt^2)/(1/dt^2+2*pi*zeta/Tn*dt))*U(m)
end
  1 comentario
TT
TT el 23 de Feb. de 2021
when evaluating function it gives Error: File: centraldiff.m Line: 1 Column: 11 Unbalanced or unexpected parenthesis or bracket. What is the error

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 24 de Feb. de 2021
When you define your function, the function declaration line should include the names of the variables into which the input arguments will be stored. It cannot contain expressions like U(1) or U(m+1).
When you call your function, specify the exact values on which you want your function to operate. The call can contain expressions.
This is an incorrect way to define the addme function:
function z = addme(2, 3)
z = 2+3;
end
This is a correct way to define the addme function:
function z = addme(x, y)
z = x + y;
end
and these are correct ways to call the addme function.
theOutput(17) = addme(2, 3)
theOutput(2) = addme(pi^2, sind(45))
See this documentation page for more information on defining functions.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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!

Translated by