Error solving for a particular variable from two equations
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Jonas Freiheit
am 5 Okt. 2021
Beantwortet: Alan Stevens
am 5 Okt. 2021
Hi all,
I am having trouble with solving for a particular variable 'a' from two equations, I end up with an error saying :
Array indices must be
positive integers or
logical values.
Error in sym/privsubsasgn
(line 1124)
L_tilde2 =
builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn
(line 961)
C =
privsubsasgn(L,R,inds{:});
Error in assignment3 (line
10)
sig_on_sigo_real(TonTc)=sig_on_sigo_2;
From the following code:
clc, clear, clear all
kB=-1.381*10^-16;
mu_H=9.274*10^-21;
J_value=0.5
syms a %Should I do this?
for TonTc=.01:0.01:.99
sig_sigo_1=((2*J_value+1)/2*J_value)*coth((2*J_value+1)/2*J_value)*a-(1/2*J_value)*coth(a/2*J_value); %First equation
sig_on_sigo_2=((J_value+1)/3*J_value)*TonTc*a; %second equation
solve(sig_sigo_1, sig_on_sigo_2); %Trying to solve for a
sig_on_sigo_real(TonTc)=sig_on_sigo_2; %subbing in the value of a I obtained from the line before
end
What should I do to properly solve for 'a'?
Cheers
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 5 Okt. 2021
You could use fzero:
TonTc = 0.01:0.01:0.99;
a = zeros(1,numel(TonTc));
a0 = 1; % initial giuess
for k = 1:numel(a)
a(k) = fzero(@(a) fn(a,TonTc(k)),a0);
end
plot(TonTc,a,'o'),grid
xlabel('TonTc'),ylabel('a')
function z = fn(a, TonTc)
J_value = 0.5;
sig_sigo_1=((2*J_value+1)/2*J_value)*coth((2*J_value+1)/2*J_value)*a-(1/2*J_value)*coth(a/2*J_value);
sig_on_sigo_2=((J_value+1)/3*J_value)*TonTc*a;
z = sig_sigo_1 - sig_on_sigo_2;
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Number Theory finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!