How do I solve for a implicit derivative?
Mostra commenti meno recenti
I need to solve for the implicit derivatives. How do have Matlab mark or view diff(u(x,y),y) as a variable that it needs to solver for?
Thanks
clear all
clc
syms x y u v;
u = sym('u(x,y)');
v = sym('v(x,y)');
g = x^2 - y^2 + u*v - v^2 +3;
h = x + y^2 + u^2 + u*v - 2;
x = 2;
y = 1;
a = diff(g)
b = diff(h)
c = diff(g,y)
d = diff(h,y)
u = -1
v = 2
[m n o p]=solve(a==0,b==0,c==0,d==0,diff(u(x,y),x),diff(u(x,y),y),diff(v(x,y),x), diff(v(x, y), y))
2 Commenti
Walter Roberson
il 29 Ott 2012
Caution #1: when you set "x = 2" after "syms x", then any expression in the symbol "x" will not have "2" substituted for "x". If you want that to happen, use subs()
Caution #2: it is much more robust to explicitly specify which variable you wish to differentiate with respect to.
Walter Roberson
il 22 Feb 2016
They are correctly taking the derivative with respect to x.
Above the point at which the derivative is taken, there is the statement
y = 1;
That overwrites the meaning of y as symbolic in the MATLAB workspace, so when
c = diff(g,y)
is called, the call is
c = diff(g,1)
which asks for the derivative to be taken 1 time with respect to the default variable. The default variable, as determined by symvar() gives first priority to x, as noted in http://www.mathworks.com/help/symbolic/symvar.html#bs_eb_i-3 and the "Algorithms" section a few lines further down.
This is why you should avoid assigning to any variable that you previously defined as symbolic and used in an expression: there is too much chance of confusion over what value the name should have after that point. Use different names for different purposes, and use subs() if you are intentionally replacing names with values.
Risposte (1)
Walter Roberson
il 29 Ott 2012
1 voto
You cannot tell the symbolic toolbox to solve for a differential expression. You need to solve for the function and then differentiate the expression. You might have to use dsolve() to solve for the function.
1 Commento
Mara Gati
il 24 Set 2018
Thanks for this!
Categorie
Scopri di più su Equation Solving in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!