How can I find parameters using ode45 function?

7 次查看(过去 30 天)
Hi, I'm just studying MATLAB... but I have a question.
How can I find parameter 'surface' when using ode45 function
here is the source code. Thanks a lot.
%%This is the function code
function [dx, *surface*] = ode_fun(t,x)
dx = zeros(2,1);
A = [0 1;-1 -(5+1.5*cos(x(1)))*x(2)-1];
B = [0;1];
lamda = 10;
*surface* = x(2) + lamda*(x(1)-5);
u = (5+1.5*cos(x(1)))*x(2)^2 + 5;
dx = A*x + B*u;
end
%%This is the main code
clear all
clc
[t, x] = ode45(@ode_fun,[0 10],[0 0]);
x_desired = 5*ones(length(x(:,1)),1);
figure(1)
plot(t,x(:,1),t,x_desired,'-.','LineWidth',2);
title('feedback linearization');
legend('x1','x desired');
xlabel('Time(s)');
ylabel('Output');
grid on;
figure(2)
plot(t,surface,'LineWidth',2);
title('Sliding Surface');
xlabel('Times(s)');
ylabel('Sliding Surface');
grid on;

回答(1 个)

Star Strider
Star Strider 2017-10-29
I would calculate it from the solved values for ‘x’:
lamda = 10;
surface = x(:,2) + lamda*(x(:,1)-5);
Unless you are returning event variables, returning extra outputs from ode45 are, to my knowledge, not supported.

类别

Help CenterFile Exchange 中查找有关 수치 적분과 미분 방정식 的更多信息

Community Treasure Hunt

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

Start Hunting!