when evaluating function it gives Error: File: centraldiff.m Line: 1 Column: 11 Unbalanced or unexpected parenthesis or bracket. What is the error
Error: File: centraldiff.m Line: 1 Column: 11 Unbalanced or unexpected parenthesis or bracket
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
TT
el 23 de Feb. de 2021
Respondida: Steven Lord
el 24 de Feb. de 2021
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
Respuesta aceptada
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))
0 comentarios
Más respuestas (0)
Ver también
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!