my code is showing not enough input argument error how to resolve

1 回表示 (過去 30 日間)
asim asrar
asim asrar 2018 年 9 月 28 日
コメント済み: asim asrar 2018 年 9 月 28 日
clear all; close all; clc;
dx=0.01;
L=20;
x=-L/2:dx:L/2-dx;
f=0*x;
f=sech(x);
plot(x,f)
dt=0.025; % integral in time in increments of 0.025
for k =1:100
t=k*dt;
[t,y]=ode45(@(t,y)rhsNEW(t,y,L),[0 dt],f);
% we are assuming ode 45 is taking a lot of little steps and we want to
% to take the last step
f(:)=y(end,:);
plot(x,real(f))
axis([-10 10 -1.5 1.5])
pause(0.1)
end
function is -
function dout=rhsNEW(t,u,L)
pi=3.14;
Nx =length(u);
uhat=fft(u);
kap=(2*pi/L)*[-Nx/2:Nx/2-1];
kap=fftshift(kap');
duhat=1i*kap.*uhat;
du=ifft(duhat);
duout=-du;

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 28 日
I tested your code and do not get that error. What I get is
Output argument "dout" (and maybe others) not assigned during call to "rhsNEW".
which is correct, as you assign to a variable named duout but not to dout.
When I change that variable name the code seems to work.
  2 件のコメント
asim asrar
asim asrar 2018 年 9 月 28 日
Dear Walter Roberson, Thanks for the response, i have changed the variable duout to dout , but it is still showing the error of not enough input argument , what changes should i need to make in my code
clear all; close all; clc; dx=0.01; L=20; x=-L/2:dx:L/2-dx; f=0*x; f=sech(x); plot(x,f)
dt=0.025; % integral in time in increments of 0.025 for k =1:100 t=k*dt; [t,y]=ode45(@(t,y)rhsNEW(t,y,L),[0 dt],f); % we are assuming ode 45 is taking a lot of little steps and we want to % to take the last step f(:)=y(end,:); plot(x,real(f)) axis([-10 10 -1.5 1.5]) pause(0.1) end
function dout=rhsNEW(t,u,L) pi=3.14; Nx =length(u); uhat=fft(u); kap=(2*pi/L)*[-Nx/2:Nx/2-1]; kap=fftshift(kap); duhat=1i*kap.*uhat; du=ifft(duhat); dout=-du;
asim asrar
asim asrar 2018 年 9 月 28 日
sorry there is no error now , thanks a-lot for the help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by