필터 지우기
필터 지우기

Vectors must be the same length

조회 수: 2 (최근 30일)
Jin Hao Yen
Jin Hao Yen 2020년 5월 5일
답변: KALYAN ACHARJYA 2020년 5월 5일
Help me please, I dont know how to solve this problem, line 47 shows 'Vectors must be the same length' , I dont know how to fix it, Thanks for taking time to see my message, Quite urgent.
  댓글 수: 4
Jin Hao Yen
Jin Hao Yen 2020년 5월 5일
I am sorry, I am new to this Matlab
Walter Roberson
Walter Roberson 2020년 5월 5일
% Creating shifted u.
u = [u(N+1:end) 1,N];
That code does not produce a shifted u. It discards most of u and appends 1 and N to the end of that.
[u(N+1:end) u(1:N)]
would be a rotated u that some might call shifted

댓글을 달려면 로그인하십시오.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 5월 5일
% This program implements an explicit scheme to solve the Burgers−Huxley
% eqution, with the addition of shifting the profile. The code ... outputs the
% travelling wave profile, with its corresponding speeds with respect to
% variation in time.
clear all; clc;
% Spacial increment.
dx = 0.1;
% Time increment.
dt = (0.95)*(1/2)*dx^2;
% Initial spacial domain.
x = [-20:dx:20];
% Time frame for simulation.
T = 600;
% Initial conditions.
u = (1-tanh(x))/2;
% Parameters k,m and n.
pk = 1; pm = 1; pn = 1;
% Defining initail states of paramters that will be used in the program.
iter = 1;
cumshift = 0;
xoffset = 0;
xpos = 0;
tm = 0;
% Implementing a shift every 300th iteration.
for j = 0:dt:T
% Applying a numerical shift every .
if (mod(iter,300)==0)
figure(1)
% Returns indices of the vector "u" that agree with the condition.
ind = find(u>0.1 & u<0.9);
% Returns the x value that corresponds to the u value at 0.5.
xc = interp1(u(ind),x(ind),0.5);
% Determining the number of steps xc is away from 0.
N = floor(xc/dx);
% Creating shift variable.
xshift = N*dx;
% Cumulated shift.
cumshift = cumshift + xshift;
% Rounding error.
xoffset = xc - xshift;
% Creating shifted u.
%u = [u(N+1:end) 1,N];
% Shifting x domain.
newx = x+cumshift;
% Plotting shifting wave solution.
plot(newx,u,'b');
axis([newx(1) newx(end) -0.1 1.1])
pause(0.01)
% Adding the total shift to a vector.
xpos = [xpos cumshift+xoffset];
% Adding the accumulated time frames between shits.
tm = [tm j];
end
% Explicit scheme.
u(2:end-1) = u(2:end-1) + ... (dt/(dx)ˆ2).*(u(3:end)−2.*u(2:end−1)+u(1:end−2)) ...
- (dt/(2*dx)).*u(2:end-1).^pk.*(u(3:end) - u(1:end-2)) ...
+ dt.*u(2:end-1).^pm.*(1-u(2:end-1).^pn);
% Boundary conditions.
u(1) = 1;
u(length(x)) = 0;
iter = iter+1;
end
% Defining parameter values.
sum = 0;
k = 0;
speed(1) = 0;
% Computing the speeds with respect to time.
for j = 2:length(xpos)
g = (xpos(j)-xpos(j-1))/(tm(j)-tm(j-1));
sum = sum + g;
k = k+1;
speed(j) = sum/k;
end
figure (4)
% Plotting a Speed vs Time graph.
plot(tm,speed)
fprintf('final speed = %1.9f\n', speed(end));

카테고리

Help CenterFile Exchange에서 Denoising and Compression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by