フィルターのクリア

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

6 ビュー (過去 30 日間)
Maria
Maria 2023 年 11 月 24 日
編集済み: Dyuman Joshi 2023 年 11 月 25 日
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 Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by