Not enough input arguments error
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi, I'm very new to MATLAB (and very bad as well) so I'm having a problem here and would be very thankfull if somebody could help me with solving it.
I'm trying to change a program but at some poit I'm getting an error "Not enogh input arguments".
This program should be giving me a surface as a result. And as an input a have some entry conditions, some boundary conditions, and a function (below).

Since the fuctions depends on two argument of which one is not actually used I put it with the power of 0. In this case it gives me "not enogh input arguments" error. In case I errase not used argument I get another error "Conversion to function_handle from double is not possible" which I don't understand at all what it means.
Thanks.
l=1;
ph=3;
u01=@(p) (abs(cos(pi*ph*((p/l)^4)))^3);
c=1;
a = 1;
b = 1;
q = 0.5;
beta1 = 0.3;
beta2 = 0.6;
phi = @(k) k*exp(-q*k);
f01 = @(p,k) exp(-a*k)*p^0;
f02= @(p,k) 0;
N = 40
h = 1/N
T = 5*l/c;
tau = 0.9*h/c
Nt = round(T/tau)
u = zeros(Nt,N);
r = c*tau/h;
x = linspace(0,l,N);
t = linspace(0,T,Nt);
for j= 1:N
if x(j)<beta1 & x(j)>beta2
f(1,j)=f02(x(j));
end
if x(j)>beta1 & x(j)<beta2
f(1,j)=f01(x(j));
end
end
for m = 1:Nt-1
u(m+1,1) = phi(t(m+1));
for i = 2:N
u(m+1,i) = 1/(r+1)*(u(m,i)+r*u(m+1,i-1)+tau*f(x(i) ,t(m)));
end
end
surf(x,t,u)
shading interp
xlabel('x')
ylabel('t')
zlabel('u')
title('u(x,t)')
1 Comment
You have mentioned two different codes, a partial error message and some code. It s not clear, which of the two versions the posted code is. Please post the real code with a complete copy of the error message, such that the readers do not have to guess, where the problem occurs.
Answers (1)
What about replacing:
for j= 1:N
if x(j)<beta1 & x(j)>beta2
f(1,j)=f02(x(j));
end
if x(j)>beta1 & x(j)<beta2
f(1,j)=f01(x(j));
end
end
by
f01 = @(x) exp(-a * x);
f = zeros(1, N);
index = (beta1 <= x & x <= beta2);
f(index) = f02(x(index));
By the way, your code ignores the value x(j)==beta1 and x(j)==beta2
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!