Question

could you please give the output of this codes clc; clear all; close all; %State Equations...

could you please give the output of this codes

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

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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT