whats wrong with this code?

8 Ansichten (letzte 30 Tage)
Nathan
Nathan am 12 Apr. 2024
Kommentiert: Star Strider am 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.

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by