d solve command matlab
4 views (last 30 days)
Show older comments
hello i just started programmig with matlab and encountered this error :
Error using symengine (line 58)
Could not extract differential variables to solve for. Use 'solve' or 'vpasolve' to compute the solutions of
non-differential equations.
Error in mupadengine/feval (line 155)
symengine('error',S(8:find(S=='[',1)-2));
Error in dsolve>mupadDsolve (line 328)
T = feval(symengine,'symobj::dsolve',sys,x,options);
Error in dsolve (line 189)
sol = mupadDsolve(args, options);
Error in hwbrownwk202016 (line 6)
solve = simplify(dsolve([diffeq,IC],symvar(V(t))))
this is the program
clear all
syms e P S A t m V0 t0 V(t) real
IC = V(0)==V0
diffeq = diff(V(t),t) == P + e*V(t) - m*(S-(V(t)))
solve = simplify(dsolve([diffeq,IC],symvar(V(t))))
the program work in the online version but not in 2013...anybody knows wat the problem is?
3 Comments
John D'Errico
on 5 Oct 2024
Um, you can still use the "old" syntax, as I show how to do so in my answer. It is completely valid in the current release.
Answers (2)
John D'Errico
on 4 Oct 2024
Edited: John D'Errico
on 4 Oct 2024
syms e P S A t m V0 t0 V(t) real
The point being that assumptions can apply only to variables, not functions. V(t) is a function of t.
IC = V(0)==V0
diffeq = diff(V(t),t) == P + e*V(t) - m*(S-(V(t)))
Next, NEVER name a variable solve!!!!!!!!!
You will be using the FUNCTION solve at aoms point intime. NAming a variable will just have you soon be posting an anguished question, asking why the solve function does not work for you.
Just call simplify with two arguments, and not inside brackets.
Vsol = simplify(dsolve(diffeq,IC))
solve =
(S*m - P + exp(t*(e + m))*(P + V0*e - S*m + V0*m))/(e + m)
1 Comment
John D'Errico
on 4 Oct 2024
Answers is still not working properly, in terms of displaying results. So I had to paste in the result from my own command window.
Rahul
on 4 Oct 2024
Hi Kees,
I believe you are trying to solve differential equations for a particular solution, involving symbolic variables and their abstract functions.
In order to use the function “diff” correctly, ‘V(t)’ can be referred to as an arbitrary symbolic function, i.e., a function with no definition. Here, the function's name is ‘V’ (like a function handle) and it is represented by the abstract formula 'V(t)', which just means that it's a function of t. When you want to take the derivative of an abstract function, pass in the name of the function, in your case, ‘V’. While evaluating the function you can use the formula, e.g., V(0), the output of which is a ‘sym’ rather than a ‘symfun’.
Here is how you restructure your code snippet:
clear all
syms e P S A t m V0 t0 V(t) real
IC = V(0)==V0
diffeq = diff(V,t) == P + e*V(t) - m*(S-(V(t)))
solve = simplify(dsolve([diffeq,IC],symvar(V(t))))
To know more about the usage of symbolic differentiation using "diff" function in MATLAB R2013a, you can use the following commands:
help sym/diff
doc sym/diff
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!