Search code examples
matlabsymbolic-mathdifferential-equations

Clarification regarding a usage in matlab


Suppose that I type the following code in matlab command window :

>> f=dsolve('D2y+y=0','y(0)=0',x)

So I get this :

>>f=
C22*sin(x)

Suppose from this I want to extract only 'sin(x)' without that C22 how do I do that ?? One more thing is I cannot add any more initial or boundary condition. Please help. Thanks


Solution

  • This code substitues all variables except those in vars_to_keep with 1

    syms x
    f=dsolve('D2y+y=0','y(0)=0',x);
    all_vars=symvar(f);
    vars_to_keep=x;
    set_to_one=setdiff(all_vars,vars_to_keep);
    for ix=1:numel(set_to_one)
        f=subs(f,set_to_one(ix),1);
    end