Matlab solving a system of equations
1 次查看(过去 30 天)
显示 更早的评论
So I have a set of equations listed below. The varying number is the value of x which goes between -0.5 and 0.5 in increments of 0.1. This is then added to 0.153 to give me a vector of values for b. These values need to be then inserted into my equations and solved.
a = 1.4;
x = -0.5:0.1:0.5;
b = 0.153 + x.^2;
eqn1= Px == dx.*75451.26;
eqn2= dx == (0.183.*578.8.*0.403)/b;
eqn3= Px == dx.*287.*Tx;
eqn4= Tx == 300/(1+0.2.*Mx.^2);
eqn5= Vx == Mx.*(401.8.*Tx).^0.5;
sol = vpasolve(eqn1,eqn2,eqn3,eqn4,eqn5);
Here are my 5 equations
0 个评论
回答(1 个)
Alan Stevens
2021-3-16
Parameters, dx, Px, Tx, Mx and Vx can be evaluated simply as follows:
a = 1.4;
x = -0.5:0.1:0.5;
b = 0.153 + x.^2;
dx = (0.183.*578.8.*0.403)./b;
Px = dx.*75451.26;
% Tx = Px./(dx.*287); But this means Tx, Mx and Vx just have constant values:
Tx = 75451.26/287;
Mx = ((300./Tx - 1)*5).^0.5;
Vx = Mx.*(401.8.*Tx).^0.5;
disp(['Tx = ',num2str(Tx)])
disp(['Mx = ',num2str(Mx)])
disp(['Vx = ',num2str(Vx)])
plot(x,Px,'--o'),grid
xlabel('x'),ylabel('Px')
6 个评论
Alan Stevens
2021-3-16
With your latest model you can no longer separate the equations - you need an iterative solution. The folowing uses fminsearch. Only you can decide if the resulting values are sensible:
a = 1.4;
x = -0.5:0.05:0.5;
b0 = 0.153;
Te = 300./(120000./7000).^(0.4./1.4);
density = 7000./(287.*Te) ;
M = ((((120000./7000).^(0.4./1.4))-1)./0.2).^0.5 ;
Ve = M.*((a.*287.*Te).^0.5);
dx0 = density.*Ve.*(0.403./b0)./ Ve;
Px0 = (7000.*(dx0.^a))./(density.^a);
Tx0 = Px0./(287.*dx0);
Mx0 = (((300./Tx0)-1)/0.2).^0.5;
Vx0 = Mx0.*((287.*1.4.*Tx0).^0.5);
K0 = [dx0; Px0; Tx0; Mx0; Vx0]; % Initial guesses
K = zeros(5,numel(x));
for i = 1:numel(x)
K(:,i) = fminsearch(@(K)fn(K,x(i)),K0);
end
% Extract variables
dx = K(1,:);
Px = K(2,:);
Tx = K(3,:);
Mx = K(4,:);
Vx = K(5,:);
plot(x,Mx,'--o'),grid
xlabel('x'),ylabel('Mx')
axis([min(x) max(x) 0 3])
function F = fn(K,x)
a = 1.4;
b = 0.153 + x.^2;
Te = 300./(120000./7000).^(0.4./1.4);
density = 7000./(287.*Te) ;
M = ((((120000./7000).^(0.4./1.4))-1)./0.2).^0.5 ;
Ve = M.*((a.*287.*Te).^0.5);
dx = K(1);
Px = K(2);
Tx = K(3);
Mx = K(4);
Vx = K(5);
dxn = density.*Ve.*(0.403./b)./ Vx;
Pxn = (7000.*(dxn.^a))./(density.^a);
Txn = Pxn./(287.*dxn);
Mxn = (((300./Txn)-1)/0.2).^0.5;
Vxn = Mxn.*((287.*1.4.*Txn).^0.5);
F = norm(dxn-dx)+norm(Pxn-Px)+norm(Txn-Tx)+norm(Mxn-Mx)+norm(Vxn-Vx);
end
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!