how to pass varibles to the function while using ODE45

hi
can someone tell me how to remove the variables in the function mentioned and include it in the arguments
function code
function out = pvar(ct,vector)
k =1.32;
Vd = 2;
r = 8.1;
R = 5.5;
P = vector(1);
W = vector(2);
Vc = Vd/(r-1);
V = Vc*(1+0.5*(r-1)*(R+1-cosd(ct)-((R^2)-((sind(ct))^2))^0.5));
dV = Vc*(r/2 - 1/2)*((pi*sin((pi*ct)/180))/180 + (pi*cos((pi*ct)/180)*sin((pi*ct)/180))/(180*(R^2 - sin((ct*pi)/180)^2)^(1/2)));
dPdt = -k*P*dV/V;
dWdt = P*dV;
out = [dPdt;dWdt;dV];
end
script
k =1.32;
Vd = 2;
r = 8.1;
R = 5.5;
IC = [112,0,Vc+Vd];
theta = [-180,0];
[ct,sol] = ode45(@pvar,theta,IC);

 採用された回答

madhan ravi
madhan ravi 2019 年 2 月 24 日

0 投票

1 件のコメント

madhan ravi
madhan ravi 2019 年 2 月 24 日
k =1.32;
Vd = 2;
r = 8.1;
R = 5.5;
Vc = Vd/(r-1);
IC = [112,0,Vc+Vd];
theta = [-180,0];
[ct,sol] = ode45(@(ct,vector)pvar(ct,vector,k,Vd,r,R,Vc),theta,IC);
figure(1)
plot(ct,sol(:,1));
title('Pressure vs. Crank Angle')
xlabel('Crank Angle (deg)')
ylabel('Pressure (kPa)')
grid
figure(2)
plot(ct,sol(:,2));
title('Work vs. Crank Angle')
xlabel('Crank Angle (deg)')
ylabel('Work (kJ)')
grid
figure(3)
plot(sol(:,3),sol(:,1))
title('Pressure vs. Volume')
xlabel('Volume (l)')
ylabel('Presure (kPa)')
grid
function out = pvar(ct,vector,k,Vd,Vc,r,R)
P = vector(1);
W = vector(2);
V = Vc*(1+0.5*(r-1)*(R+1-cosd(ct)-((R^2)-((sind(ct))^2))^0.5));
dV = Vc*(r/2 - 1/2)*((pi*sin((pi*ct)/180))/180 + (pi*cos((pi*ct)/180)*sin((pi*ct)/180))/(180*(R^2 - sin((ct*pi)/180)^2)^(1/2)));
dPdt = -k*P*dV/V;
dWdt = P*dV;
out = [dPdt;dWdt;dV];
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

質問済み:

2019 年 2 月 24 日

コメント済み:

2019 年 2 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by