[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help Plotting Symbolic Vector Fields with Substitutions
From: |
Mike Miller |
Subject: |
Re: Help Plotting Symbolic Vector Fields with Substitutions |
Date: |
Tue, 18 Apr 2017 11:39:51 -0700 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Mon, Apr 17, 2017 at 16:13:04 -0700, WARDEVIL_UFO wrote:
> https://www.mathworks.com/help/symbolic/create-plots.html
> <http://https://www.mathworks.com/help/symbolic/create-plots.html>
>
>
> I am attempting a quiver plot of symbolic functions starting with the
> following example from MatLab. It appears the substitution gets hung up
> some reason.
There are many shortcomings with the subs function. Quoting from the end
of "help @sym/subs":
Note: There are many possibilities that we don’t support (FIXME) if
you start mixing scalars and matrices. We support one simple case
of subbing a matrix in for a scalar in a scalar expression:
f = sin(x);
g = subs(f, x, [1 2; 3 4])
⇒ g = (sym 2×2 matrix)
⎡sin(1) sin(2)⎤
⎢ ⎥
⎣sin(3) sin(4)⎦
If you want to extend support to more cases, a good place to start,
as of July 2014, is the Sympy Issue #2962
[https://github.com/sympy/sympy/issues/2962].
This is probably an area where the symbolic package maintainer (and
maybe even the SymPy folks) could use some help. But it's probably not
going to be able to do this kind of operation as it stands today.
> syms x y
> u = sin(x^2 + y^2);
> v = cos(x*y);
> [X, Y] = meshgrid(-1:.1:1,-1:.1:1);
> U = subs(u, [x y], {X,Y});
> V = subs(v, [x y], {X,Y});
> quiver(X, Y, U, V)
I can sort of work around this with the following
U = arrayfun (@ (a, b) double (subs (u, [x, y], {a, b})), X, Y);
V = arrayfun (@ (a, b) double (subs (v, [x, y], {a, b})), X, Y);
Note that this is extremely slow because it is performing a symbolic
substitution for every pairwise X and Y, casting the result to a numeric
value, and collecting the results into the resulting arrays. But the end
result looks correct.
--
mike
- Help Plotting Symbolic Vector Fields with Substitutions, WARDEVIL_UFO, 2017/04/18
- Re: Help Plotting Symbolic Vector Fields with Substitutions,
Mike Miller <=
- Re: Help Plotting Symbolic Vector Fields with Substitutions, Colin Macdonald, 2017/04/19
- Re: Help Plotting Symbolic Vector Fields with Substitutions, WARDEVIL_UFO, 2017/04/21
- Re: Help Plotting Symbolic Vector Fields with Substitutions, Colin Macdonald, 2017/04/21
- Re: Help Plotting Symbolic Vector Fields with Substitutions, Colin Macdonald, 2017/04/21