Clear Filters
Clear Filters

whats wrong with this code?

1 view (last 30 days)
Nathan
Nathan on 12 Apr 2024
Commented: Star Strider on 12 Apr 2024
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.

Answers (1)

Star Strider
Star Strider on 12 Apr 2024
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 Comments
Nathan
Nathan on 12 Apr 2024
i copied your code and it worked some seems identical but it worked
Star Strider
Star Strider on 12 Apr 2024
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.)

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!