Filter löschen
Filter löschen

Vectors must be the same length

1 Ansicht (letzte 30 Tage)
Jin Hao Yen
Jin Hao Yen am 5 Mai 2020
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 Kommentare
Jin Hao Yen
Jin Hao Yen am 5 Mai 2020
I am sorry, I am new to this Matlab
Walter Roberson
Walter Roberson am 5 Mai 2020
% 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 5 Mai 2020
% 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));

Kategorien

Mehr zu Denoising and Compression finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by