Solving an equation with two vectors
이전 댓글 표시
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개)
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}))
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
