How to solve the error "[t, z]= ode45(@observer, t_temp,z0)" in line 23.
3 views (last 30 days)
Show older comments
Meenakshi Tripathi
on 19 Jan 2021
Commented: Meenakshi Tripathi
on 20 Jan 2021
function will
clc
global E A B C N P L M x0 tspan u
E=[0.5 -2.5 0;3 -3 4;2 -1 3];
A=[-1 4.5 -0.5;-7 7 -8;-5 3 -6];
B=[1 0 1;0 1 1;1 0 -1];
C=[1 0 1];
N=[-0.75 -1 0.25;0 -2 0;0.25 1 -0.75];
L = [51.3257 11.2723;41.5581 7.8378;-24.3673 -6.2663];
M = [-0.4488 2.4167;-0.0898 0.4833;0.2693 -1.4500];
R = [0.3565 0.6582;0.1578 -0.2295;-0.3565 -0.6582]
B1= [-0.7306 -0.8299 -0.5319;0.4742 0.0304 1.3620]
P = R*B1
x0 = [1 0 -1];
tspan = 0:.1:20;
[x,y]=solbasic;
function dzdt = observer(t,z)
dzdt=N*z+L*[(y(i,:)+y(i+1,:))/2]'+P*u;
end
z0=[10 11 6];
for i = 1:length(y)-1;
t_temp =((i-1)/10):.05:(i/10);
[t,z]=ode45(@observer,t_temp,z0);
end
z1;
x;
x_cap=z+y*M';
e=x-x_cap;
end
function [x,y] = solbasic()
%y is the output which we will get after finding value of x
global E tspan x0 C
opt = odeset('RelTol',1e-6,'Mass',E);
[~, x] = ode15s(@basic, tspan, x0, opt)
y = x*C';
end
function dxdt = basic(t,x)
global A B u
u=[exp(-t)*sin(t);0.2*sin(2*t);0.2*sin(3*t)];
dxdt=A*x+B*u;
end
My errors are-
Error using odearguments (line 93)
WILL/OBSERVER must return a column vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in will (line 23)
[t,z]=ode45(@observer,t_temp,z0);
0 Comments
Accepted Answer
Mischa Kim
on 19 Jan 2021
dzdt seems to be a (3x2 ?) matrix. It needs to be a 3x1 vector to be consistent with the initial conditions, z0, which is also a 3-component vector.
function dzdt = observer(t,z)
dzdt = N*z + L*[(y(i,:)+y(i+1,:))/2]' + P*u;
end
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!