I've been playing with this for awhile, Can anyone explain why I get different answers from Code1 and Code2? What is it about the actual script of 'dsolve()' that makes the output of the 2 codes different? Could the output be the same if I just used different syntax (ie ',;".')?
%Code1:
syms Qua t Area height
rate_in = 3*Qua*(sin(t))^2;
delta_Vol = dsolve('DAreaY = rate_in - Qua');
delta_Height= dsolve('Dheight = ((rate_in - Qua)/Area)', 'height(0) = 0');
subfnc1 = subs(rate_in, {Qua}, {450});
fnc1 = subs(delta_Height, {'rate_in'}, {subfnc1});
fnc1 = subs(fnc1, {Area, Qua}, {1250,450});
fnc_main = matlabFunction(fnc1);
fnc_main(0:10)';
%Code2:
syms Qua t Area height
rate_in = 3*Qua*(sin(t))^2;
delta_Vol = dsolve('DAreaY = 3*Qua*(sin(t))^2 - Qua');
delta_Height= dsolve('Dheight = ((3*Qua*(sin(t))^2 - Qua)/Area)', 'height(0) = 0');
fnc1 = subs(delta_Height, {Area, Qua}, {1250,450});
fnc_main = matlabFunction(fnc1);
fnc_main(0:10)';
what is it about the dsolved function that I don't understand?
The problem might be that you're passing strings to
dsolverather than symbolic expressions. This means that in the first caserate_imight be interpreted as a constant, rather than a function oft.Here's what you're probably trying to do: defining
Dheightas asymas well, and tellingdsolvewhat to do usingsyms:Changes to your version:
delta_Volsince it wasn't used and contained an unclear reference to(D)AreaYdsolvefrom string to symbolic expression, in the mean time=had to be changed to==DHeightasdiff(Height), which implies thatheighthas to be declared asheight(t). This also allows us to define the initial condition asheight(0)==0, otherwise we'd have needed to keep this a string:'height(0)=0'.Now both versions return the same solution:
I suggest checking on paper whether this solution, or its symbolic predecessor,
is indeed a solution to your differential equation.