Error using Cos, not enough input arguments

1 visualización (últimos 30 días)
Ned Sara
Ned Sara el 5 de Abr. de 2019
Comentada: Stephen23 el 5 de Abr. de 2019
Hello, I'm having a problem with the cosine and sine functions in MatLab. I'm trying to replicate the effect of a plasma actuator in matlab which involves adding a source term that replicates the effect. The source term involve a Guassian function;
a = (cos^2*(pi/2)/2*Ox^2) + (sin^2*(pi/2)/2*Oy^2);
b = (-(sin*2*(pi/2)/4*Ox^2 + (sin*2*(pi/2)/4*Oy^2)));
c = (sin^2*(pi/2)/2*Ox^2) + (cos^2*(pi/2)/2*Oy^2);
with the source term being;
Su = A*exp(-(a(x-xc)^2 + 2*b(x-xc)*(y-yc) + x(y-yc)^2));
when i try running, it says error using cos, not enough input arguments. Does anyone know where im going wrong?
Thanks

Respuesta aceptada

Stephen23
Stephen23 el 5 de Abr. de 2019
Editada: Stephen23 el 5 de Abr. de 2019
cos^2*(pi/2) % incorrect
cos(pi/2)^2 % correct
Your code has several other syntax errors, such as:
Ox % what does this mean?
Oy % what does this mean?
and
b(...) % if this is supposed to be multiplication, then you actually need:
b*(...)
You should learn basic MATLAB concepts by doing the introdcutory tutorials:
and also reading the documentation for every operation that you use, no matter how trivial you think it might be. You should also learn about vectorized code:
  2 comentarios
Ned Sara
Ned Sara el 5 de Abr. de 2019
Editada: Stephen23 el 5 de Abr. de 2019
Ox and Oy were reffering to sigma x and sigma y in the Guassian Function
clear; close all;
nx=101; ny=101; nt=500; nit=50;
xmin=-5; xmax=5;
ymin=0; ymax=8;
dx = (xmax-xmin)/(nx-1);
dy = (ymax-ymin)/(ny-1);
x = linspace(xmin,xmax,nx);
y = linspace(ymin,ymax,ny);
[X,Y] = meshgrid(x,y);
rho=1.225;
nu=0.000001;
dt=0.0000001;
source_posx = -2;
source_posy = 0;
source_h = 1;
source_w = 1.5;
A=0.5;
sigma_x = 0.5;
sigma_y = 0.5;
x = 2;
xc = 0.2;
y = 2;
yc = 0.2;
a = ((cos(pi/2)^2)/2*sigma_x^2) + ((sin(pi/2)^2)/2*sigma_y^2);
b = (-(sin*2*(pi/2)/4*sigma_x^2) + (sin*2*(pi/2)/4*sigma_y^2));
c = (sin(pi/2)^2)/(2*sigma_x^2) + (cos(pi/2)^2)/2*sigma_y^2;
% Source term
Su = A*exp(-(a*(x-xc)^2 + 2*b*(x-xc)*(y-yc) + c*(y-yc)^2));
Sv = 0.1;
% Init
u=zeros(ny,nx);
v=zeros(ny,nx);
p=zeros(ny,nx);
b=zeros(ny,nx);
%Pressure Field
%Square Brackets of Poissons Equation
for it = 1:nt+1
for i=2:(nx-1)
for j=2:(ny-1)
b(i,j)=rho*(1/dt*((u(i+1,j)-u(i-1,j))/(2*dx)+(v(i,j+1)-v(i,j-1))/(2*dy))-((u(i+1,j)-u(i-1,j))/(2*dx))^2-2*((u(i,j+1)-u(i,j-1))/(2*dy)*(v(i+1,j)-v(i-1,j))/(2*dx))-((v(i,j+1)-v(i,j-1))/(2*dy))^2);
end
end
for iit=1:nit+1
pn=p;
for i=2:(nx-1)
for j=2:(ny-1)
p(i,j)=((pn(i+1,j)+pn(i-1,j))*dy^2+(pn(i,j+1)+pn(i,j-1))*dx^2)/(2*(dx^2+dy^2))-dx^2*dy^2/(2*(dx^2+dy^2))*b(i,j);
end
end
p(:,ny) = p(:,ny-1); %%dp/dy = 0 at y = 2
p(1,:) = p(2,:); %%dp/dy = 0 at y = 0
p(:,1) = p(:,2); %%dp/dx = 0 at x = 0
p(:,ny) = 0; %%dp = 0 at y = 2
end
un = u;
vn = v;
for j=2:nx-1
for i=2:ny-1
%Velocity Field
% U components:
u1 = un(i,j)*dt/dx*(un(i,j)-un(i-1,j));
v1 = vn(i,j)*dt/dy*(un(i,j)-un(i,j-1));
px = dt/(2*rho*dx)*(p(i+1,j)-p(i-1,j));
ux = dt/dx^2*(un(i+1,j)-2*un(i,j)+un(i-1,j));
uy = dt/dy^2*(un(i,j+1)-2*un(i,j)+un(i,j-1));
% V components:
u2 = un(i,j)*dt/dx*(vn(i,j)-vn(i-1,j));
v2 = vn(i,j)*dt/dy*(vn(i,j)-vn(i,j-1));
py = dt/(2*rho*dy)*(p(i,j+1)-p(i,j-1));
vx = dt/dx^2*(vn(i+1,j)-2*vn(i,j)+vn(i-1,j));
vy = dt/dy^2*(vn(i,j+1)-2*vn(i,j)+vn(i,j-1));
inxrng = (X(i,j) >= source_posx-(0.5*source_w)) && (X(i,j) <= source_posx+(0.5*source_w));
inyrng = (Y(i,j) >= source_posy-(0.5*source_h)) && (Y(i,j) <= source_posy+(0.5*source_h));
u(i,j) = un(i,j)-u1-v1-px+nu*(ux + uy);
v(i,j) = vn(i,j)-u2-v2-py+nu*(vx + vy);
% Add source term
if inxrng && inyrng
u(i,j) = u(i,j) + Su;
v(i,j) = v(i,j) + Sv;
end
end
u(1,:)=0;
u(:,1)=0;
u(nx,:)=0;
u(:,ny)=0;
v(1,:)=0;
v(ny,:)=0;
v(:,1)=0;
v(nx,:)=0;
end
%surf(x,y,u)
% %contourf(x,y,sqrt(u.^2+v.^2),'linestyle','None')
% quiver(x,y,u,v,5)
% axis equal
% pause(0.05)
%surf(x,y,u)
%pause(0.001)
end
quiver(x,y,u,v,5)
axis equal
pause(0.05)
That is the full code if it makes sense
Stephen23
Stephen23 el 5 de Abr. de 2019
Learn how to write vectorized code.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Axis Labels en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by