Clear Filters
Clear Filters

Error using vertcat and how to solve it?

11 views (last 30 days)
Hello everyone, I am getting Error using vertcat, Dimensions of arrays being concatenated are not consistent, error for the following code. Can anyone please point me out my error and how to fix it.
clc
clear all
f = @(t,x) [-x(4)-(0.424)+(1.6977)*exp(-1.35*10^20*(x(1)^2));
x(4)-(0.663)+(2.6540)*exp(-1.35*10^20*(x(2)^2));
-(2.994*10^5)*x(4);
(7.124*10^17*(x(1)^2)-7.124*10^17*(x(2)^2)+x(3)+60*(cos(t))) -2.55*10^7*x(4)];
[t,xa] = ode45(f,[0, 80],[0,0,-62,0]);

Accepted Answer

Stephen23
Stephen23 on 7 Feb 2023
Edited: Stephen23 on 7 Feb 2023
f = @(t,x) [-x(4)-(0.424)+(1.6977)*exp(-1.35*10^20*(x(1)^2));
x(4)-(0.663)+(2.6540)*exp(-1.35*10^20*(x(2)^2));
-(2.994*10^5)*x(4);
(7.124*10^17*(x(1)^2)-7.124*10^17*(x(2)^2)+x(3)+60*(cos(t)))-2.55*10^7*x(4)];
% ^^ removed space character
A space character is a delimiter that separates elements horizontally, equivalent to a comma. Because of that space character you were trying to concatenate rows together which had [1,1,1,2] columns. Clearly that doesn't work.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!