%I'm doing the Mixture of 2 salts equation and I would to like to add a
%dirac with the purpose in the real life to add just once 2lb of salt in this
%tank.
%So basically, I have a constat flow going in and out to this tank, and I
%want to add 2lb of salt in this tank just one time and I need do it with
%the dirac delta function.
syms A(t) y
%f = diff(A) == Kin * A
%dsolve(f)
% k*A = the solution concentration
% A: amount of salt k: amount of water
Kin = 3;
Ain = 2;
Kout = 3;
Ain = Kin*Ain;
Aout = Kout * (A/300);
x=0:15;
idx = y == Inf;
y(idx) = 1;
% After 5 minutes 2 lb the salt will be added just once.
f1 = diff(A) == (Ain - Aout) + (2 * dirac(x-5))
f1(t) = 
S = dsolve(f1)
Warning: Number of equations greater than number of indeterminates. Trying heuristics to reduce to square system.
Error using mupadengine/feval_internal
Unable to reduce to square system because the number of equations differs from the number of indeterminates.

Error in dsolve>mupadDsolve (line 334)
T = feval_internal(symengine,'symobj::dsolve',sys,x,options);

Error in dsolve (line 203)
sol = mupadDsolve(args, options);
S1 = dsolve(S,A(0)==50,t)
plot(x,S,'o-')
title 'Mixture of 2 salts'
xlabel ('Time (min)')
ylabel ('Amount of Salt (lb)')

 Réponse acceptée

Paul
Paul le 16 Oct 2022
Hi Adrielli,
Why is Ain defined and then redefined? Is that correct?
What is the role of the x and y variables in this problem?
f1(t) is a 1 x 16 array becasue x has 16 elements and is used in the defintion of f1(t). Why is x used here at all, insofar as t is the independendent variable.
Mabye the code should be:
syms A(t) y
%f = diff(A) == Kin * A
%dsolve(f)
% k*A = the solution concentration
% A: amount of salt k: amount of water
Kin = 3;
Ain = 2;
Kout = 3;
Ain = Kin*Ain;
Aout = Kout * (A/300);
%x=0:15;
%idx = y == Inf;
%y(idx) = 1;
% After 5 minutes 2 lb the salt will be added just once.
f1 = diff(A) == (Ain - Aout) + (2 * dirac(t-5)) % change x to t
f1(t) = 
S = dsolve(f1)
S = 

3 commentaires

Adrielli
Adrielli le 16 Oct 2022
Answer your questions:
Why is Ain defined and then redefined? Is that correct?
It was a fool mistake giving the name to the variable. My to intend was the amount of water+salt pumped in the tank was Ain=6. I just should rename one of these variables.
What is the role of the x and y variables in this problem?
I would like my X was the time, so when I reach the 5 minutes my dirac delta function should add the amount of salt I set it up.
I'm using the Y to setting my dirac funcion.
Honestly, I'm learning how to use the matlab, so maybe I just make a huge mess.
f1(t) is a 1 x 16 array because x has 16 elements and is used in the definition of f1(t). Why is x used here at all, insofar as t is the independent variable?
About this, I was trying to plot it in some way, trying to do it work. So probably, it is just a mess I did in a frustated tryied.
Let me try explain it again...
I had this mixture of 2 salts problem that I already solved (I'll add the image problem and the code at matlab).
What I'm trying to do now is: I want to add just one time 2lb of salt in this tank, and I need to do it using the dirac delta funtion.
syms A(t)
Kin = 2;
Ain1 = 3;
Kout = 3;
Ain = Kin*Ain1;
Aout = Kout * (A/300);
f1 = diff(A) == Ain - Aout
dsolve(f1);
dsolve(f1,A(0)==50,t)
The code you've posted matches the solution in the book, though it's using A(t) as the unknown function instead of x(t)
syms A(t)
Kin = 2;
Ain1 = 3;
Kout = 3;
Ain = Kin*Ain1;
Aout = Kout * (A/300);
f1 = diff(A) == Ain - Aout
f1(t) = 
dsolve(f1);
Asol = dsolve(f1,A(0)==50) % deleted the third input argument
Asol = 
Same solution as is in the text.
Now, if we want to modify Ain, which has units of lb/min if I'm reading the problem correctly, s.t. the A(t) has step change of 2 lb at t = 5 min, then we can do as you propose, which is to modify Ain with the properly scaled delta function:
f2 = lhs(f1) == rhs(f1) + 2 * dirac(t - 5)
f2(t) = 
Asol1 = dsolve(f2,A(0)==50,t)
Asol1 = 
Plot both solutions over a ling time scale. They look very siimilar, which shiouldn't be surprising.
figure;
fplot([Asol Asol1],[0 1000])
But we see the 2 lb step change if we zoom in
figure
fplot([Asol Asol1],[4 6])
Another way to solve this problem would be to solve the first ode from t = 0 t = 5. Then take the end state A(5), add 2 lb, and use that as the boundary condition to sovle same ode from t = 5 forwards. The total solution for A(t) would be the piecewise function formed from the two solutions.
Adrielli
Adrielli le 16 Oct 2022
Thank you. Undoubtedly you managed to clarify all my doubts and I could understand how to use matlab to solve this problem.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by