Azzera filtri
Azzera filtri

Error while plotting sym function

2 visualizzazioni (ultimi 30 giorni)
Satyabrat
Satyabrat il 11 Gen 2023
Risposto: Aditya Jha il 16 Gen 2023
Hello,
I have prepared a code as follows:
%A check for initial tilt angle k
syms v
I = input("Body moment of inertia? in kgm^2"); % I = 150kgm^2
l = input("Length of body? in m "); % l= 0.5m
b = input("Breadth of body? in m "); % b= 0.13m
w = input("Height of body? in m "); % w= 0.5m
d = input("cross-section diameter of towed array? in m "); % d= 0.72m
h = input("length of towed array? in m "); % h= 4.713m
s = input("span of hydrofoil? in m "); % s= 0.53m
c = input("chord of hydrofoil? in m "); % c=0.15m
yf = input("y-coordinate of application of hydrofoil force? in m "); % yf= 0.2
xf = input("x-coordinate of application of hydrofoil force? in m "); % xf= 0.2
yc = input("y-coordinate of application of towed array force? in m "); % yc= 0.2
xc = input("x-coordinate of application of towed array force? in m "); % xc= 2.606
yt = input("y-coordinate of application of towing force? in m"); % yt= 0.25
xt = input("x-coordinate of application of towing force? in m"); % xt= 0
yb = input("y-coordinate of application of body force? in m"); % yb=
xb = input("x-coordinate of application of body force? in m"); % xb= 0
xcm = input("center of gravity x-coordinate?"); % xcm= 1.3724m
ycm = input("center of gravity y-coordinate?"); % ycm= 0.0985m
xcb = input("center of buoyancy x-coordinate?"); % xcb= 1.3724m
ycb = input("center of buoyancy y-coordinate?"); % ycb= 0.0985m
lf = ycm+yf;
bf = xcm-xf;
lc = yc-ycm;
bc = xc-xcm;
lt = yt-ycm;
bt = xcm;
lb = ycm+yb;
bb = xcm;
lB = ycb-ycm;
bB = xcb-xcm;
beta = input("Hydrofoil angle of attack? in rad "); %beta= 0.17 radians, 10 degrees
AR = s/c; %Aspect ratia of hydrofoil
k = input("Initial tilt? in m/s "); %v= 10m/s
%Cdc = input("Drag coefficient cable? "); %Cdc= 0.82
%Clc = input("Lift coefficient cable? "); %Clc= 0
Cf = input("Skin friction coefficient"); %Ct=Cn=Cf=0.012
Cdp = input("profile drag coefficient"); %Cdp=0.82
Cdc = Cf*cosd(k); %Cdc= 0.82
Clc = Cf*sind(k)+Cdp*(sind(k)^2); %Clc= 0
Cd = input("Drag coefficient body? "); %Cd= 2.05
Cl = input("Lift coefficient body? "); %Cl= 0
Clf = 2*pi*(AR/(AR+3))*beta; %Lift coefficient of hydrofoil
Cdf = (Clf^2)/(pi*AR); %drag coefficient of hydrofoil
rhow = input("Fluid density? in kg/m^3 "); %rhow= 1000kg/m^3
rhos = input("Stabiliser density? in kg/m^3"); %rhow= 1483.68kg/m^3
rhoc = input("Towed array density? in kg/m^3 "); %rhoc= 1000kg/m^3
%v = input("Velocity? in m/s "); %v= 10m/s
pi = 3.14;
xk = xcm*cosd(k)+ycm*sind(k); %center of mass x-coordinate after some tilt k
yk = -xcm*sind(k)+ycm*cosd(k); %center of mass y-coordinate after some tilt k
Vb = l*b*w; %Body volume
Mb = rhos*Vb; %Body mass
Mwb = rhow*Vb; %Body displaced water mass
Vf = 2*5*s*0.12*c*(0.1979*(c^1.5)-0.063*(c^2)-0.1172*(c^3)+0.0711*(c^4)-0.0203*(c^5)); %Hydrofoil volume
Mf = rhos*Vf; %Hydrofoil mass
Mwf = rhow*Vf; %Hydrofoil displaced water mass
Vc = pi*((d/2)^(2))*h; %towed array volume
Mc = rhoc*Vc; %towed array mass
Mwc = rhow*Vc; %towed array displaced water mass
B = (Mwb+2*Mwf+2*Mwc)*9.81; %Buoyant force
W = (Mb+2*Mf+2*Mc)*9.81; %Body weight
%Dc = 0.5*Cdc*rhow*(v^2)*(2*pi*(d/2)*h); %Towed array drag force
%Lc = 0.5*Clc*rhow*(v^2)*(2*pi*(d/2)*h); %Towed array lift force
Dc = 0.5*Cdc*rhow*(v^2)*((d)*h); %Towed array drag force
Lc = 0.5*Clc*rhow*(v^2)*((d)*h); %Towed array lift force
Db = 0.5*Cd*rhow*(v^2)*l*b; %Body drag force
Lb = 0.5*Cl*rhow*(v^2)*w*b; %Body lift force
Lf = 0.5*Clf*rhow*(v^2)*s*c*cos(beta); %Hydrofoil lift force
Df = 0.5*Cdf*rhow*(v^2)*s*c*sin(beta); %hydrofoil drag force
theta = atand((-2*Lc-Lb-2*Lf-B+W)/(Db+2*Dc+2*Df)); %angle between horizontal and T? in deg
T = (2*Dc+Db+2*Df)/cosd(theta);
%theta = atand((-2*Lc-Lb-B+W)/(Db+2*Dc)); %angle between horizontal and T? in deg
%T = (2*Dc+Db)/cosd(theta);
%A(v) = (sind(k)*(2*Dc*lc-2*Dc*yk-2*Lc*bc+2*Lc*xk-Db*yk+Lb*xk-2*Df*yk-2*Df*lf+2*Lf*xk-2*Lf*bf-T*cosd(theta)*lt+T*cosd(theta)*yk-T*sind(theta)*xk+T*sind(theta)*bt)+cosd(k)*(2*Lc*lc-2*Lc*yk+2*Dc*bc-2*Dc*xk-Lb*yk-Db*xk-2*Lf*yk-2*Lf*lf-2*Df*xk+2*Df*bf+T*sind(theta)*lt-T*sind(theta)*yk+T*cosd(theta)*xk-T*cosd(theta)*bt))/I; %with fins
%A(v) = (sind(k)*(2*Dc*lc-2*Dc*yk-2*Lc*bc+2*Lc*xk-Db*yk+Lb*xk-T*cosd(theta)*lt+T*cosd(theta)*yk-T*sind(theta)*xk+T*sind(theta)*bt)+cosd(k)*(2*Lc*lc-2*Lc*yk+2*Dc*bc-2*Dc*xk-Lb*yk-Db*xk+T*sind(theta)*lt-T*sind(theta)*yk+T*cosd(theta)*xk-T*cosd(theta)*bt))/I; %without fins
%A(v) = (sind(k)*(2*Dc*lc-2*Dc*yk-2*Lc*bc+2*Lc*xk-Db*yk+Lb*xk-2*Df*yk-2*Df*lf+2*Lf*xk-2*Lf*bf)+cosd(k)*(2*Lc*lc-2*Lc*yk+2*Dc*bc-2*Dc*xk-Lb*yk-Db*xk-2*Lf*yk-2*Lf*lf-2*Df*xk+2*Df*bf))/I; %with fins without T
%A(v) = (sind(k)*(2*Dc*lc-2*Dc*yk-2*Lc*bc+2*Lc*xk-Db*yk+Lb*xk)+cosd(k)*(2*Lc*lc-2*Lc*yk+2*Dc*bc-2*Dc*xk-Lb*yk-Db*xk))/I; %without fins without T
%A(s) = (sind(k)*(2*Dc*lc-2*Lc*bc-2*Df*lf-2*Lf*bf) + cosd(k)*(2*Lc*lc+2*Dc*bc-2*Lf*lf+2*Df*bf))/I; %with fins
%A(v) = (sind(k)*(2*Dc*lc-2*Lc*bc) + cosd(k)*(2*Lc*lc+2*Dc*bc))/I; %without fins
%A(v) = (sind(k)*(2*Dc*lc-2*Lc*bc-2*Df*lf-2*Lf*bf-T*cosd(theta)*lt-T*sind(theta)*bt) + cosd(k)*(2*Lc*lc+2*Dc*bc-2*Lf*lf+2*Df*bf+T*sind(theta)*lt-T*cosd(theta)*bt))/I; %with fins
%A(v) = (sind(k)*(2*Dc*lc-2*Lc*bc-T*cosd(theta)*lt-T*sind(theta)*bt) + cosd(k)*(2*Lc*lc+2*Dc*bc+T*sind(theta)*lt-T*cosd(theta)*bt))/I; %without fins
A(v) = ( Lc*lc+Dc*bc-Lf*lf-Df*bf-Lb*lb-Db*bb+T*sind(theta)*lt+T*cosd(theta)*bt+B*lB); %with fins
%A(v) = ( Lc*lc+Dc*bc-Lb*lb-Db*bb+T*sind(theta)*lt+T*cosd(theta)*bt+B*lB); %without fins
v = linspace(10,30);
plot(v, A(v));
grid on;
xlabel('Towed array force');
ylabel('Variation of A');
It shows the following error:
Error using sym/subsindex
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
Error in Initial_tilt (line 92)
A(v) = ( Lc*lc+Dc*bc-Lf*lf-Df*bf-Lb*lb-Db*bb+T*sind(theta)*lt+T*cosd(theta)*bt+B*lB); %with fins
Related documentation
It shows the quantity A to be a double and not a sym function.
Can someone please provide any help regarding this?
Thanks in advance

Risposte (1)

Aditya Jha
Aditya Jha il 16 Gen 2023
Hi!
Please refer to the following MATLAB Answers post with a similar query where function body must be a sym : https://www.mathworks.com/matlabcentral/answers/576544-error-using-sym-subsindex

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by