필터 지우기
필터 지우기

Solving an equation with 2 known arrays

조회 수: 4 (최근 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 CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by