How to solve a differential equations system?

I have the equations system below:
d(na)/dt=-r*V;
d(nw)/dt=-r*V;
d(nb)/dt=-r*V;
d(H)/dt=-AhU*(6*T-360);
H=na*(DhfA+Cpa*(T-25))+nb*(DhfB+Cpb*(T-25))+nw*(DhfW+Cpw*(T-25));
V=(na/pa)+(nb/pb)+(nw/pw);
r=Ko*exp(EdiaR/T)*na/V;
with na,nw,nb,V,r,t,H the unknown functions and na(0)=10 and nb(0)=20
this is my code below but it doesn't seem to work at all. Any help please?
syms na nw nb V T H r ;
c1=na(0)==10;
c2=nw(0)==20;
eqn1=diff(na)==-r*V;
eqn2=diff(nw)==-r*V;
eqn3=diff(nb)==-r*V;
eqn4=diff(H)==-AhU*(6*T-360);
eqn5=H==na*(DhfA+Cpa*(T-25))+nb*(DhfB+Cpb*(T-25))+nw*(DhfW+Cpw*(T-25));
eqn6=V==(na/pa)+(nb/pb)+(nw/pw);
eqn7=r==Ko*exp(EdiaR/T)*na/V;
S=dsolve(eqn1,eqn2,eqn3,eqn4,eqn5,eqn6,eqn7,c1,c2)

Answers (3)

The system is too complex to be solved with dsolve.
Use a numerical solver instead (e.g. ODE15S).
You will also need initial values for nb and H.
Best wishes
Torsten.
You did not declare na to be a function, so diff(na) is going to be 0 (or maybe 1).
When you use diff() to express the form, you should use functional form, like diff(na(t),t)

2 Comments

This is my code for a more simple system that i wrote to catch the feeling: but it gives me this error:
??? Error using ==> syms at 61
Not a valid variable name.
any idea? :/
clc;
close all;
clear all;
syms f(t) g(t);
c1=f(0)==0;
c2=g(0)==0;
eqn1 = diff(f(t),t) == 3*f + 4*g;
eqn2 = diff(g(t),t) == -4*f + 3*g;
S = dsolve(eqn1, eqn2, c1, c2)
R2011a does not support function notation for syms. Use
syms f g t
c1 = f(0)==0;
c2 = g(0)==0;
eqn1 = diff(f(t),t) == 3*f(t) + 4*g(t);
eqn2 = diff(g(t),t) == -4*f(t) + 3*g(t);
S = dsolve(eqn1, eqn2, c1, c2)
I do not recall at the moment whether R2011a supported symbolic "==". You might need to use
c1 = f(0) - 0;
c2 = g(0) - 0;
Remove the ";" after the syms declaration.
Maybe it will also be necessary to replace
eqn1 = diff(f(t),t) == 3*f + 4*g;
eqn2 = diff(g(t),t) == -4*f + 3*g;
by
eqn1 = diff(f) == 3*f + 4*g;
eqn2 = diff(g) == -4*f + 3*g;
, but I'm not sure.
Best wishes
Torsten.

3 Comments

Thank you very much! :) could i get the error because I'm using the 2011a version? :/
You still get the error ? Or did it vanish after the changes ?
If the error persists, you should consult the MATLAB 2011a documentation. I'm sure there are examples for the use of "dsolve" with two unknown functions plus initial conditions.
Best wishes
Torsten.
Ok thank you very much! :-)

This question is closed.

Asked:

on 20 Oct 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!