필터 지우기
필터 지우기

Error using vertcat Dimensions of arrays being concatenated are not consistent.

조회 수: 6 (최근 30일)
Hello. When I start the program, I get an error about using vertcat, I don’t understand why, I tried to find information and fix it, but apparently I’m missing something. What can I do to solve the problem?
function f=M86()
n = 1;b=1; k = -4; a = 1; h = 3; p = (1/4)*pi; y(1)=0;y(2)=1;x=2;
f=[y(2);y(2)+2.*n.*(1+a.*y.^3).*y(1)+k.^2.*(y(1)+b.*y(1).^3)-h.*sin(p.*x)];
clc
disp('Значения параметров: n = 1,b=2, k = -4, a = 1, h = 3,b =2, p = (1/4)*Pi')
disp('Решение задачи Коши для уравнения')
[~,y] = ode45('f',[0,1],[0,0],1,2,-4,1,3,2,(1./4).*pi);
plot(y(:,1),y(:,2))
tic,[~,~]=ode45('M86',[-1,1],[0,0],1,2,-4,1,3,2,(1./4).*pi);toc
grid on
end
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 11월 24일
Note by the way that using a character vector (or string scalar) as the name of the ode function is recommended against. You should use a function handle instead.
When you use a character vector (or string scalar) then the function named must have its own .m file (or be a .mdl or .slx or .p). In particular, it cannot be the name of a function that is in the same file as the ode45* call.
Walter Roberson
Walter Roberson 2023년 11월 24일
disp('Значения параметров: n = 1,b=2, k = -4, a = 1, h = 3,b =2, p = (1/4)*Pi')
Значения параметров: n = 1,b=2, k = -4, a = 1, h = 3,b =2, p = (1/4)*Pi
disp('Решение задачи Коши для уравнения')
Решение задачи Коши для уравнения
[~,y] = ode45(@f,[0,1],[0,0],1,2,-4,1,3,2,(1./4).*pi);
Unrecognized function or variable 'f'.

Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
plot(y(:,1),y(:,2))
tic,[~,~]=ode45(@M86,[-1,1],[0,0],1,2,-4,1,3,2,(1./4).*pi);toc
grid on
function f=M86()
n = 1;b=1; k = -4; a = 1; h = 3; p = (1/4)*pi; y(1)=0;y(2)=1;x=2;
f=[y(2);y(2)+2.*n.*(1+a.*y.^3).*y(1)+k.^2.*(y(1)+b.*y(1).^3)-h.*sin(p.*x)];
end

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

채택된 답변

Torsten
Torsten 2023년 11월 25일
편집: Torsten 2023년 11월 25일
Maybe you mean something like this.
I don't know whether it must read y(1) or y(2) at the place marked in bold letter in the next line ; I assumed y should be y(1).
f=@(t,y)[y(2);y(2)+2.*n.*(1+a.*y.^3).*y(1)+k.^2.*(y(1)+b.*y(1).^3)-h.*sin(p.*x)];
M86()
Значения параметров: n = 1,b=1, k = -4, a = 1, h = 3, p = (1/4)*Pi Решение задачи Коши для уравнения
function M86
n = 1;b=1; k = -4; a = 1; h = 3; p = (1/4)*pi; y(1)=0;y(2)=1;x=2;
f=@(t,y)[y(2);y(2)+2.*n.*(1+a.*y(1).^3).*y(1)+k.^2.*(y(1)+b.*y(1).^3)-h.*sin(p.*x)];
disp('Значения параметров: n = 1,b=1, k = -4, a = 1, h = 3, p = (1/4)*Pi')
disp('Решение задачи Коши для уравнения')
[~,y] = ode45(f,[0,1],[0,0]);
plot(y(:,1),y(:,2))
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by