Question

please give the output of the following code: clc; clear all; close all; %State Equations syms...

please give the output of the following code:

clc;

clear all;

close all;

%State Equations

syms x1 x2 p1 p2 u;

x2 = [0.9974 0.0539;-0.1078 1.1591].*x1 + [0.0013;0.0539]*u;

%Cost function in the sigma

syms g;

g = 0.5*(0.25*(x1)^2 + 0.05*(x2)^2 + 0.05*u^2);

%Hamiltonian

Dp1 = -diff(H,x1);

Dp2 = -diff(H,x2);

%Solve for control u

du = diff(H,u);

sol_u = solve(du,'u');

%Substitute u to state equations

Dx2 = subs(Dx2, u, sol_u);

%Convert symbolic objexcts to strings

eq1 = srcat('Dx1=', char(Dx1));

eq2 = strcat('Dx2=', char(Dx2));

eq3 = strcat('Dp1=', char(Dp1));

eq4 = strcat('Dp2=', char(Dp2));

sol_h = dsolve(eq1,eq2,eq3,eq4);

Homework Answers

Answer #1

In the given code you forgot to declare H, better use strcat in eq1

clc;

clear all;

close all;

%State Equations

syms x1 x2 p1 p2 u;

Dx1 = x2;

Dx2 = -x1 - 2*x2 + u;

%Cost function in the integral

syms g;

g = 0.5*((x1)^2 + 2*(x2)^2 + u^2);

%Hamiltonian

syms H;

Dp1 = -diff(H,x1);

Dp2 = -diff(H,x2);

%Solve for control u

du = diff(H,u);

sol_u = solve(du,'u');

%Substitute u to state equations

Dx2 = subs(Dx2, u, sol_u);

%Convert symbolic objexcts to strings

eq1 = strcat('Dx1=', char(Dx1));

eq2 = strcat('Dx2=', char(Dx2));

eq3 = strcat('Dp1=', char(Dp1));

eq4 = strcat('Dp2=', char(Dp2));

sol_h = dsolve(eq1,eq2,eq3,eq4);

output

reading values from struct

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions