How to change values for variables that are defined in a equation

47 ビュー (過去 30 日間)
Delia Bosshart
Delia Bosshart 2021 年 4 月 16 日
回答済み: Walter Roberson 2021 年 4 月 19 日
Hello everybody!
I have an equation depending on several variables (a, b, c, d) . By defining the values new and wanting the adapted output, it still takes the values for the variables that I defined first (for fist and second set the output is x=1.4321). How can I ressolve that? I dont want to change the names of the variables as I have more than 80 different values for the same variable.
See my code:
%first set of values for variables
a = 75; %q_inc
b = 13.8; %q_losses
c = 73; %rho_char
d = 1.02; %betta_char
syms x
eqn = (a - b + 6.96*x + (6-(31*c)/1000)*x/60*1000 + 31*c/1000*d/60*1000)*0.0081 - 0.1824 -x == 0;
vpasolve(eqn,x)
ans = 1.4231
%second set of values for variables
a = 96.4; %q_inc
b = 14.1; %q_losses
c = 100.6; %rho_char
d = 1.32; %betta_char
vpasolve(eqn,x)
ans = 1.4231

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 19 日
syms a b c d
syms x
eqn = (a - b + 6.96*x + (6-(31*c)/1000)*x/60*1000 + 31*c/1000*d/60*1000)*0.0081 - 0.1824 -x == 0;
sol = solve(eqn, x)
sol = 
A = [75, 96.4];
B = [13.8, 14.1];
C = [73, 100.6];
D = [1.02, 1.32];
subs(sol, {a,b,c,d}, {A,B,C,D})
ans = 

その他の回答 (2 件)

Alan Stevens
Alan Stevens 2021 年 4 月 16 日
Since your equation is linear in x it's probably best to rewrite as in the following, and put all your a,b,c,d vaues into vectors:
a = [75, 96.4];
b = [13.8, 14.1];
c = [73, 100.6];
d = [1.02, 1.32];
x = ((a - b + 31*c/1000.*d/60*1000)*0.0081 - 0.1824)./(1 - 0.0081*(6.96 + (6-31*c/1000)/60*1000));
disp(x)
1.4231 1.8750
  1 件のコメント
Delia Bosshart
Delia Bosshart 2021 年 4 月 19 日
Thank you Alan for your answer! Unfortunately my equation will look like this in a further step:
eqn2 = (a - b + 6.96*x + (6-(31*232.87*((x-e)*t)^(-0.46))/1000)*x/60*1000 + 31*d/1000*e/60*1000)*0.0081 - 0.1824 -x == 0;
The equation in not linear anymore and I can't solve it by hand anymore which is why i will need the solve function.
I tried this:
x = sym('x', [1 2]);
vpasolve(eqn2, x);
But then the output gives me a struct of names (x1, x2) instead of the values of x1 and x2

サインインしてコメントする。


Alan Stevens
Alan Stevens 2021 年 4 月 19 日
More like this perhaps (of course you will need to use your on values for the constants):
a = [75, 96.4];
b = [13.8, 14.1];
c = [73, 100.6];
d = [1.02, 1.32];
e = [0.1, 0.2]; t = [0.3, 0.4]; % replace with your values
syms x
for i = 1:numel(a)
eqn2 = (a(i) - b(i) + 6.96*x + (6-(31*232.87*((x-e(i))*t(i))^(-0.46))/1000)*x/60*1000 + 31*d(i)/1000*e(i)/60*1000)*0.0081 - 0.1824 -x == 0;
y = vpasolve(eqn2,x);
disp(y)
end

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by