Azzera filtri
Azzera filtri

d solve command matlab

15 visualizzazioni (ultimi 30 giorni)
Kees
Kees il 4 Ott 2024
Commentato: John D'Errico il 5 Ott 2024 alle 12:27
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
Warning: Can only make assumptions on variable names, not 'V(t)'.
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 Commenti
Kees
Kees il 4 Ott 2024
hello Rahul, great and thanx! spend hours on this but in the end it was just a syntax difference between the old en new version..
John D'Errico
John D'Errico il 5 Ott 2024 alle 12:27
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.

Accedi per commentare.

Risposte (2)

John D'Errico
John D'Errico il 4 Ott 2024
Modificato: John D'Errico il 4 Ott 2024
syms e P S A t m V0 t0 V(t) real
Warning: Can only make assumptions on variable names, not 'V(t)'.
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 Commento
John D'Errico
John D'Errico il 4 Ott 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.

Accedi per commentare.


Rahul
Rahul il 4 Ott 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
Warning: Can only make assumptions on variable names, not 'V(t)'.
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

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by