whats wrong with this code?

1 次查看(过去 30 天)
Nathan
Nathan 2024-4-12
function [drag] = aero_drag(dens,v,A)
Fd = 0.5 .* dens .* (v.^2) .* A .* 0.55.*sign(v);
drag = Fd
File: areo_drag.m Line: 1 Column: 10
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.

回答(1 个)

Star Strider
Star Strider 2024-4-12
It works here.
How are you calling your ‘aero_drag’ function?
dens = rand
dens = 0.3011
v = rand
v = 0.7408
A = randn(1,5)
A = 1x5
0.2096 -1.3985 0.6751 1.1753 -0.3353
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
drag = aero_drag(dens,v,A)
drag = 1x5
0.0095 -0.0635 0.0307 0.0534 -0.0152
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
function [drag] = aero_drag(dens,v,A)
Fd = 0.5 .* dens .* (v.^2) .* A .* 0.55.*sign(v);
drag = Fd;
end
.
  2 个评论
Nathan
Nathan 2024-4-12
i copied your code and it worked some seems identical but it worked
Star Strider
Star Strider 2024-4-12
Thank you!
It may simply have needed an end, or alternatively, needed to be put at the end of your script. (I’m not certain, because I don’t know where it was in your script, or how you called it.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by