Solving an equation with two vectors
22 ビュー (過去 30 日間)
古いコメントを表示
I am trying to solve for an unknown using an equation with two vectors. I have tried using solve but the output is a 0x1 vector. I am trying to solve for p in the equation below and want a 37411x1 vector output with all the solutions. I considered using linsolve, but it looks like that only works for equations with one vector.
TotalDensity=WaterContent{:,2};%37411x1 vector
Drydensity=WaterContent{:,5};%37411x1 vector
syms p
eqn = TotalDensity==p*.99819+(1-p)*Drydensity;
S=solve(eqn,p);
1 件のコメント
Torsten
2022 年 1 月 13 日
TotalDensity=WaterContent{:,2};%37411x1 vector
Drydensity=WaterContent{:,5};%37411x1 vector
TotalDensity = cell2mat(TotalDensity);
DryDensity = cell2mat(DryDensity);
p = (TotalDensity - DryDensity)./(.99819 - DryDensity)
回答 (1 件)
Walter Roberson
2022 年 1 月 13 日
You have 37411 equations in one single variable. There is no value, p, such that all of the equations are satisfied simultaneously.
solve() is for simultaneous equations. For example,
syms x y
solve([x + y == 5, 3*x + 4*y == 5])
Notice that this does not attempt to solve for ((x + y == 5) OR (3*x + 4*y == 5)) -- it solves for ((x + y == 5) AND (3*x + 4*y == 5))
There are two strategies:
- For linear equations and low-degree polynomials, solve a template and then subs() in the actual numeric values to get the vector of results; OR
- for nonlinear equations, loop doing one equation at a time, perhaps using arrayfun()
syms TD DD p
eqn = TD == p*.99819+(1-p)*DD;
S = solve(eqn, p)
%some numeric values for testing
TotalDensity = rand(4,1), Drydensity = rand(4,1).^2
%get numeric solutions
SN = double(subs(S, {TD, DD}, {TotalDensity, Drydensity}))
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!