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 次查看(过去 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
采纳的回答
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))
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!