Kindly help me out with this code. its urgent please .thanks
2 ビュー (過去 30 日間)
古いコメントを表示
c=5.916;
h=35;
a=-11.5;
b=180;
q1=0;
q2=0;
p1=0.2;
E=0.2;
p2=sqrt(2*E- p1^2)
K=[0 0.0189 0.0190 2.2];
m=length(K);
dt=1/5;
tspan=[100:dt:1000];
for c=1:m;
[t{c},x{c}]=ode23tb(@(t,x)HB(t,x,c,h,a,b,K(c)),tspan,[q1 q2 p1 p2]);
end
X1=x{:,1};
X2=x{:,2};
X3=x{:,3};
X4=x{:,4};
subplot(2,2,1)
plot(X1(:,1),X1(:,3),'b',X1(:,2),X1(:,4),'r','LineWidth',5.0)
ax = gca;
ax.FontSize = 20; % Font Size of 15
legend('P','q')
title('(a)')
ylabel("P")
xlabel("q")
subplot(2,2,2)
plot(X2(:,1),X2(:,3),'b',X2(:,2),X2(:,4),'r','LineWidth',1.2)
ax = gca;
ax.FontSize = 20; % Font Size of 15
title('(b)')
ylabel("P")
xlabel("q")
subplot(2,2,3)
plot(X3(:,1),X3(:,3),'b',X3(:,2),X3(:,4),'r','LineWidth',1.2)
ax = gca;
ax.FontSize = 20; % Font Size of 15
title('(c)')
ylabel("p")
xlabel("q")
subplot(2,2,4)
plot(X4(:,1),X4(:,3),'b',X4(:,2),X4(:,4),'r','LineWidth',1.5)
ax = gca;
ax.FontSize = 20; % Font Size of 15
title('(d)')
ylabel("P")
xlabel("q")
function dxdt = HB(t,x,b,c,a,h,K)
dxdt = zeros(4,1);
dxdt(1) = x(3);
dxdt(2) = x(4);
dxdt(3) =-((((2*h.*sin.*x(1))./(cos^3.*(x(1))))+((c.*(cos^2)*x(1)+2.*(sin^2).*x(1))./((cos^3).*x(1)))-(b.*sin*2.*x(1))+(a.*cos.*x(1)))+ K*(x(2)-x(1)));
dxdt(4) =-((((2*h.*sin.*x(2))./(cos^3.*(x(2))))+((c.*(cos^2)*x(2)+2.*(sin^2).*x(2))./((cos^3).*x(2)))-(b.*sin*2.*x(2))+(a.*cos.*x(2)))+ K*(x(1)-x(2)));
end
2 件のコメント
Steven Lord
2023 年 6 月 21 日
What help are you looking to receive? You haven't asked a question or indicated the nature of the problem you're experiencing with this code.
Walter Roberson
2023 年 6 月 21 日
Is it "Send an ambulance!" urgent, or is it "Illegally pull over to the side of the side of the express highway to answer" urgent, or is it "Cancel my meeting with my cardiac surgeon!" urgent?
採用された回答
Steven Lord
2023 年 6 月 21 日
Looking at one sample line from your HB function:
dxdt(3) =-(((2*h*sin*x(1))/((cos)^3*(x(1))))+((c*(cos^2)*x(1)+2*(sin)^2*x(1))/((cos)^3*x(1)))-(b*(sin)*2*x(1))+(a*(cos)*x(1)))+ K*(x(2)-x(1));
None of sin*x(1), (cos)^3*(x(1)), (cos^2)*x(1), etc. will work.
To compute the sine of an angle call the sin function with an input. The same holds for cosine and the cos function.
sin(pi/2)
To compute a power of the sine or cosine of an angle call the sin or cos functions and raise the result to a power.
sin(pi/3)^2 % sine squared of pi/3
Yes, I know mathematically that operation is usually written but that's not how it's written in code. Think instead.
0 件のコメント
その他の回答 (1 件)
Torsten
2023 年 6 月 21 日
編集済み: Torsten
2023 年 6 月 21 日
The trigonometric functions sin, cos for an argument x are invoked as sin(x), cos(x),...
If they have an exponent, they are either sin(x^3), cos(x^3),... or (sin(x))^3, (cos(x))^3 depending on what you want to do.
sin.*x(1) cos^3.*(x(1)) etc. like in your code make no sense.
3 件のコメント
Torsten
2023 年 6 月 21 日
Didn't you read what I wrote ? You didn't change anything in your sin and cos expressions in function HB.
Walter Roberson
2023 年 6 月 21 日
sin*x(1) asks matlab to invoke the sin function with no parameters, and multiply the results by x(1). However, matlab does not permit invoking sin with no parameters. If the intent is to invoke sin with an empty parameter use sin([])*x(1)
参考
カテゴリ
Help Center および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!