Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Warning: Input arguments must be scalar.

Subject: Warning: Input arguments must be scalar.

From: Christos Mountrichas

Date: 29 Dec, 2012 12:21:07

Message: 1 of 4

Hi everyone,

I created a script to solve the diffusion equation for a specific situation. However, although i get the right results, I am getting the "Warning: Input arguments must be scalar" message.

Please, I would appreciate any help.

Here is the code:
%
clear; clf; % clean file and clear figure
 xmax = 10; % input length of domain in x direction
 tmax = 4; % input end time
 D = 5.435; % input diffusion coefficient
 cb1=0.4; cb2=0; % input boundary concentrations
 dx = 1; % input gap between two x coordinates (x=0,1,2...10)
 dt = 0.5*dx^2/D; % input time increment
 nx=fix(xmax/dx)+1; % total number of x(i)
 mt=fix(tmax/dt)+1; % total number of t(j)
 r=D*dt/dx^2; s=1-2*r;
 t = [0: dt: tmax]; % t(j)
 x = [0, dx: xmax]; % x(i)
 c = zeros(1:nx,1); c(1,1)=cb1; c(nx,1)=cb2; % c(i,j) at t=0
 %
 % Generate remaining rows of C
 for j = 2: mt
    c(1,j)=cb1;
for i = 2: nx-1
c(i,j) = s*c(i, j-1) + r*(c(i-1,j-1)+c(i+1,j-1));
end;
    c(nx,j)=cb2;
 end;
Cx=c';
t1=fix(1/dt)+1; t2=fix(2/dt)+1; t3=fix(4/dt)+1;
plot(x,c(:,t1),'r-', x,c(:,t2),'b--', x,c(:,t3),'g:'); hold on;
xlabel('x(i)'); ylabel('c(i,j)'); hold on

Subject: Warning: Input arguments must be scalar.

From: dpb

Date: 29 Dec, 2012 21:04:35

Message: 2 of 4

On 12/29/2012 6:21 AM, Christos Mountrichas wrote:
...

> I created a script to solve the diffusion equation for a specific
> situation. However, although i get the right results, I am getting the
> "Warning: Input arguments must be scalar" message.
> Please, I would appreciate any help.
...

dbstop on warning % doc debug & friends

--

Subject: Warning: Input arguments must be scalar.

From: Sadik

Date: 30 Dec, 2012 02:05:23

Message: 3 of 4

Hi Christos,

It is right this command:

c = zeros(1:nx,1);

You should have used:

c = zeros(nx,1);

Best.

Subject: Warning: Input arguments must be scalar.

From: Christos Mountrichas

Date: 30 Dec, 2012 10:11:08

Message: 4 of 4

Oh thank you so much Sadik !!
It now works just fine!!!!

Best wishes

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us