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

1 次查看(过去 30 天)
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 个评论
TT
TT 2021-2-23
when evaluating function it gives Error: File: centraldiff.m Line: 1 Column: 11 Unbalanced or unexpected parenthesis or bracket. What is the error

请先登录,再进行评论。

采纳的回答

Steven Lord
Steven Lord 2021-2-24
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by