Solving an equation with two vectors
22 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Torsten
il 13 Gen 2022
TotalDensity=WaterContent{:,2};%37411x1 vector
Drydensity=WaterContent{:,5};%37411x1 vector
TotalDensity = cell2mat(TotalDensity);
DryDensity = cell2mat(DryDensity);
p = (TotalDensity - DryDensity)./(.99819 - DryDensity)
Risposte (1)
Walter Roberson
il 13 Gen 2022
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 Commenti
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!