Solving an equation with 2 known arrays

3 ビュー (過去 30 日間)
Oded Ben Tsedek
Oded Ben Tsedek 2020 年 12 月 21 日
回答済み: Sreeranj Jayadevan 2020 年 12 月 30 日
I'm trying to solve equation with 1 variable (k) but 2 vectors (x and t).
I need to get an array of answers for k, such as (k[i] = eqn(t[i],x[i]).
This is what I wrote:
t = [28.35 53.34 85.39 132.7];
x = linspace(0.01,0.04,4);
k = sym ('k',[1 4]);
eqn = T-Ti==(2*q*sqrt((t.*k)/(c*p*pi))./k)*exp(((-x.^2)*c*p)./(4*k.*t))-((q*x)./k)*erfc(x/(2*sqrt((t.*k)/(c*p))));
solk = solve(eqn,k);
solk.k1
solk.k2
solk.k3
solk.k4
and of course it doesn't work.
How do I fix it?

回答 (1 件)

Sreeranj Jayadevan
Sreeranj Jayadevan 2020 年 12 月 30 日
Your code is working as expected. I was able to execute the same when a different equation was used. Check if the equation you are using contain dimensional mismatches.
The following code works:
x=sym('x', [1 4]);
y=[1 2 3 4];
z=[2 3 4 5];
sol=solve(x.*y+z+1==0,x); % You can change this equation
sol.x1
sol.x2
sol.x3
sol.x4
% Converting it into an array of type double
temp=struct2cell(sol);
sol_arr=double([temp{:}]);
"sol_arr" returns the array of answers that you require.

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by