Substitute 3 variables in this symbolic equation
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, i have a big symbolic equation containing w, x, y as the symbolic variables.
Something similar to http://www.mathworks.com/matlabcentral/answers/35371-error-while-converting-a-huge-symbolic-equation-to-double-question-edited-and-simplified-further however it contains w also.
I now want to substiute w in the equation also. The previous answer to my question was
subs(subs(Wnet, x, 5:5:30)', y, 1100:100:1500) subs(subs(SFC, x, 5:5:30)', y, 1100:100:1500)
However, i want to add w to it from 1:0.5:3 How do i do it?
0 commentaires
Réponses (4)
Christopher Creutzig
le 11 Mai 2012
And then, there's always
>> [X, Y, W] = ndgrid(5:5:30, 1100:100:1500, 1:0.5:3);
>> subs(Wnet, {x, y, w}, {X, Y, W})
3 commentaires
Alexander
le 11 Mai 2012
Maybe in this case the suggestion from Walter scales better:
[X, Y, Z] = ndgrid(5:5:30, 1100:100:1500, 1:0.5:3);
WnetF = matlabFunction(Wnet, 'vars', [x, y, z]);
WnetN = double(arrayfun(WnetF, X, Y, Z));
Christopher Creutzig
le 11 Mai 2012
Or, expanding on the thing you have:
>> syms x y z
>> f = 3*x + 2*y + z;
>> subs(subs(subs(f, x, 1:4), y, (1:3)'), z, reshape(1:3,1,1,3))
ans(:,:,1) =
6 9 12 15
8 11 14 17
10 13 16 19
ans(:,:,2) =
7 10 13 16
9 12 15 18
11 14 17 20
ans(:,:,3) =
8 11 14 17
10 13 16 19
12 15 18 21
(For symmetry, you could also write the (1:3)' as reshape(1:3,1,3).)
Compared to Alexander's solution (which works just fine, afaics), this may (or may not) be faster, since it only inserts each x-value once. It is also a way in which you can get symbolic results, e.g., a result still containing a. (Alexander's solution has the advantage of doing most of the work in MATLAB, not in symbolics, which often is faster.)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!