Substitute 3 variables in this symbolic equation

7 Ansichten (letzte 30 Tage)
Vaibhav
Vaibhav am 11 Mai 2012
Hi, i have a big symbolic equation containing w, x, y as the symbolic variables.
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?

Antworten (4)

Christopher Creutzig
Christopher Creutzig am 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 Kommentare
Vaibhav
Vaibhav am 11 Mai 2012
Example of what i meant to say above through an example script.
clear
h=[1,2,3,4,5,]; %height
syms w x y
t0=w; %temperature (depends on h, there's no equation to it!)
p0=x; %pressure (depends on h, there's no equation to it!)
m=y; %another variable which is completely independent
Wnet=3.*t0 + 2.*p0 + m.^2;
x1=subs(subs(Wnet, {w,x}, {250:10:280,15000:5000:30000})', y, 0.5:0.5:3);
%means for h = 1,t0=250,p0=15000
%h = 2,t0=260,p0=20000
%so in real, h and y is what i want to get in the 5x5 array.
Vaibhav
Vaibhav am 11 Mai 2012
h=[1,2,3,4] ***
i think the code i typed works :P
evaluating my answers

Melden Sie sich an, um zu kommentieren.


Alexander
Alexander am 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));
  1 Kommentar
Vaibhav
Vaibhav am 11 Mai 2012
i made a mistake in my question
Example of what i meant to say above through an example script.
clear
h=[1,2,3,4,5,]; %height
syms w x y
t0=w; %temperature (depends on h, there's no equation to it!)
p0=x; %pressure (depends on h, there's no equation to it!)
m=y; %another variable which is completely independent
Wnet=3.*t0 + 2.*p0 + m.^2;
x1=subs(subs(Wnet, {w,x}, {250:10:280,15000:5000:30000})', y, 0.5:0.5:3);
%means for h = 1,t0=250,p0=15000
%h = 2,t0=260,p0=20000........
%so in real, h and y is what i want to vary and substitute to get the 5x5 array.

Melden Sie sich an, um zu kommentieren.


Christopher Creutzig
Christopher Creutzig am 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.)
  1 Kommentar
Vaibhav
Vaibhav am 11 Mai 2012
I made a mistake in expressing my question.
I have to substitute 3 variables, but i have to convert 2 variables to one.
i have a matrix for height which is h=[1,2,3,4,5]
Now for h=[1,2,3,4,5]
the values of w and x are
w=[0.5:0.5:3]
x=[5:5:30]
They correspond to the same values of h
y is as it is.
What i somewhat mean is
subs(subs(Wnet, {w,x}, {0.5:0.5:3,5:5:30})', y, 1100:100:1500)
subs(subs(SFC, {w,x}, {0.5:0.5:3,5:5:30})', y, 1100:100:1500)
How do i tackle this?

Melden Sie sich an, um zu kommentieren.


Vaibhav
Vaibhav am 11 Mai 2012
The code i type worked :D
But still, i got to learn lots for your answers above.
Lots of codes and stuff to try and learn.
Thanks for the help guys =)
clear
h=[1,2,3,4,5,]; %height
syms w x y
t0=w; %temperature (depends on h, there's no equation to it!)
p0=x; %pressure (depends on h, there's no equation to it!)
m=y; %another variable which is completely independent
Wnet=3.*t0 + 2.*p0 + m.^2;
x1=subs(subs(Wnet, {w,x}, {250:10:280,15000:5000:30000})', y, 0.5:0.5:3);
%means for h = 1,t0=250,p0=15000
%h = 2,t0=260,p0=20000
%so in real, h and y is what i want to get in the 5x5 array.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by