I want to create an equation in matlab and for each one variable that is unknown it can solve it directly.
For example I sign every variable to equal a number and solve for Cj.
Below is my coding to solve for Cj.
However I want to create an equation that let say if I have Cj known and I want to find H or y it can solve it without me having to creat another equation to solve for it
mdot = 115; % Source Strength g/s
U = 6.82; % Wind speed m/s
h = 62.6; % Stack Height (m)
Sh = 25.5; % Plume Rise Height (m)
H = h + Sh; % Effective Stack Height (m)
x = 2; % X location (m)
y = 0; % Y location (m)
z = 1.49; % Z location (m)
% Dispersion Coefficients
a = 68;
b = 0.894;
c = 44.5;
d = 0.516;
f = -13;
% Dispersion Coefficients
Sigma_Y = a * (x^b);
Sigma_Z = c * (x^d) + f;
% Exp
e1 = exp((-1/2)*((y/Sigma_Y)^2 + ((z-H)/Sigma_Z)^2));
e2 = exp((-1/2)*((y/Sigma_Y)^2 + ((z+H)/Sigma_Z)^2));
% Equation for Gaussian concentration for absorbing ground
Cj1 = (mdot * e1) / (2*pi*U*Sigma_Y*Sigma_Z);
Cj_Absorbing = Cj1 * 10^6;
% Equation for Gaussian concentration for reflective ground
Cj1 = (mdot * (e1 + e2)) / (2*pi*U*Sigma_Y*Sigma_Z);
Cj_Reflecting = Cj1 * 10^6;

5 commentaires

Benjamin Thompson
Benjamin Thompson le 22 Fév 2022
Modifié(e) : Benjamin Thompson le 22 Fév 2022
You could use the Symbolic Math Toolbox. There are a lot of examples here:
Star Strider
Star Strider le 22 Fév 2022
Torsten
Torsten le 22 Fév 2022
Example:
syms x y
expr = 3*x^2 + sin(y) == 0;
solx = solve(expr,x)
soly = solve(expr,y)
Abdullah Alsayegh
Abdullah Alsayegh le 22 Fév 2022
its will solve as an equation can it solve it as a number if I give all the variables = number and find one variable?
Torsten
Torsten le 22 Fév 2022
syms x y
expr = 3*x^2 + sin(y) == 0;
solx = solve(expr,x);
solx = double(subs(solx,y,0.3))
soly = solve(expr,y);
soly = double(subs(soly,x,0.2))

Connectez-vous pour commenter.

 Réponse acceptée

David Hill
David Hill le 22 Fév 2022
Modifié(e) : David Hill le 22 Fév 2022

0 votes

function Output = solveE(Input,guess)
%Input is an array [U,mdot,H,z,y,sigmaY,sigmaZ,Cj] of all values except nan
%for the variable you want to solve for.
syms U mdot H y z sigmaY sigmaZ Cj
eqn=mdot/(2*pi*U*sigmaY*sigmaZ)*exp(-0.5*((y/sigmaY)^2+((z-H)/sigmaZ)^2))-Cj==0;
switch find(isnan(Input))
case 1
Output=vpasolve(subs(eqn,[mdot,H,z,y,sigmaY,sigmaZ,Cj],Input(2:8)),U,guess);
case 2
Output=vpasolve(subs(eqn,[U,H,z,y,sigmaY,sigmaZ,Cj],Input([1,3:8])),mdot,guess);
case 3
Output=vpasolve(subs(eqn,[U,mdot,z,y,sigmaY,sigmaZ,Cj],Input([1:2,4:8])),H,guess);
case 4
Output=vpasolve(subs(eqn,[U,mdot,H,y,sigmaY,sigmaZ,Cj],Input([1:3,5:8])),z,guess);
case 5
Output=vpasolve(subs(eqn,[U,mdot,H,z,sigmaY,sigmaZ,Cj],Input([1:4,6:8])),y,guess);
case 6
Output=vpasolve(subs(eqn,[U,mdot,H,z,y,sigmaZ,Cj],Input([1:5,7:8])),sigmaY,guess);
case 7
Output=vpasolve(subs(eqn,[U,mdot,H,z,y,sigmaY,Cj],Input([1:6,8])),sigmaZ,guess);
case 8
Output=vpasolve(subs(eqn,[U,mdot,H,z,y,sigmaY,sigmaZ],Input(1:7)),Cj,guess);
end

6 commentaires

Abdullah Alsayegh
Abdullah Alsayegh le 22 Fév 2022
Thankk you so much for taking your time.I am new to matlab and I just want to know now how I can use it if let say i have all the variables and I want to solve for y ?
Added a guess for the value you are trying to find.
mdot = 115; % Source Strength g/s
U = 6.82; % Wind speed m/s
h = 62.6; % Stack Height (m)
Sh = 25.5; % Plume Rise Height (m)
H = h + Sh; % Effective Stack Height (m)
x = 2; % X location (m)
y = 0; % Y location (m)
z = 1.49; % Z location (m)
% Dispersion Coefficients
a = 68;
b = 0.894;
c = 44.5;
d = 0.516;
f = -13;
% Dispersion Coefficients
Sigma_Y = a * (x^b);
Sigma_Z = c * (x^d) + f;
k=[U,mdot,H,z,y,Sigma_Y,Sigma_Z,nan];%move the nan to different spots to get other results
Cj=solveE(k,1)%function call
Cj =
9.7124e-05
Abdullah Alsayegh
Abdullah Alsayegh le 23 Fév 2022
I am getting a error after running the code.
David Hill
David Hill le 23 Fév 2022
Save the function, then run the above script in the command line.
Abdullah Alsayegh
Abdullah Alsayegh le 23 Fév 2022
Modifié(e) : Abdullah Alsayegh le 23 Fév 2022
Thank you so much for helping me on this it worked so perfect.
One quick question, if i need to set up my variable x to be x = 1:1:10 can it work on this function? because I am planning to plot this to >> plot (x,y) however the answer showing for y is >> Empty sym: 0-by-1
the plot should be similar to this picture
Walter Roberson
Walter Roberson le 23 Fév 2022
? your equation has no x, and your code has no x, so I do not see where you would put x=1:1:10 ?
If you are doing symbolic work and you put a vector into vpasolve() or solve() then those functions need to solve the set of equations simultaneously . For example if you had 3*x == z and you wanted to know z and you put in x = [1, 2] then it would be trying to solve [3 == z, 6 == z] simultaneously , which would fail. vpasolve() and solve() are for simultaneous equations .

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by