Need help with three interdependent differential equation. Not able to obtain accurate graph.

1 次查看(过去 30 天)
Simultaneous first-order ordinary differential equations: dv/dx= 2P/r - [C(x) - Co] where v = 0 at x = 0; dC/dx=B where C = Co=0.30 at x = L; and dB/dx=(C(dv/dx)+vB-2N/r)/D
Where N=10^-5 when x≤10 And N=0 when x>10
I'm trying to graph C and V with respect to by using a forward finite method.
nsteps= 1000;
Co= 0.3;
N=(1*(10^-5)) ;
D= (1*(10^-5));
R= 0.05;
P= (2*(10^-5));
W= (2*P)/R;
z1= 0;
z2= 0.75;
z3= 0;
dx= 0.1;
xplot= zeros(1, nsteps);
z1plot= zeros(1, nsteps);
z2plot= zeros(1, nsteps);
z3plot= zeros(1, nsteps);
for j= 1:nsteps
x= j*dx;
if x<=10
N==N;
else
N==0;
if x<=100
z2==0.3;
else
z2==z2;
z1= ((W*(z2-Co)*dx)+z1);
z2= ((z3*dx)+z2);
z3= ((((W/D)*z2*(z2-Co))+ ((z1*z3)/D)- ((2*N)/(R*D)))*dx)+z3;
xplot(j)=x;
z1plot(j)=z1;
z2plot(j)=z2;
z3plot(j)= z3;
end
end
end
plot(xplot, z2,'x')
I don't know whats wrong.

回答(1 个)

RahulTandon
RahulTandon 2015-7-8
%% Simultaneous first-order ordinary differential equations: clc; syms x v(x) C(x) C0 B L N(x) r E clear; %% cannot use D as a variable!! str1 = 'Dv == 2*P/r - [C(x) - Co]'; str2 = 'v(0) = 0'; str3 = 'DC == B '; str4 ='C(L) = Co'; str5 = 'C0 = 0.30'; str6 = 'dB/dx == (C*Dv+v*B-2*N/r)/E';
str7 = 'N(9) = 10^-5'; % when x<=10 str8 = 'N(11) = 0'; % when x>10
[C,v] = dsolve(str1,str2,str3,str4,str5,str6,str7,str8,'x')

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by