Category: Matlab
Category Archives: Matlab
How do I compute bandpower?
Which parts of this code is correct? I’m getting confused on which sections are relevant for my question above?
N = length(sig1);
xdft1 = fft(sig1);
xdft1 = xdft1(1:N/2+1);
psdx1 = (1/(Fs*N)) * abs(xdft1).^2;
psdx1(2:end-1) = 2*psdx1(2:end-1);
freq1 = 0:Fs/length(sig1):Fs/2;
P1_band = psdx1(freq1 >= 20 & freq1 <= 100);
f1_band = freq1(freq1 >= 20 & freq1 <= 100);
power_sig1 = trapz(f1_band, P1_band);
noise = x_new – x_notch;
SNR_dB = snr(x_notch, noise);
P_signal = mean(signalSeg.^2, ‘omitnan’);
P_noise = mean(noiseSeg.^2, ‘omitnan’);
SNR_dB = 10*log10(P_signal / P_noise);
f_notch = 60;
BW_notch = 2;
wo = f_notch/(Fs/2);
Q = f_notch/BW_notch;
bw = wo/Q;
[b_n,a_n] = iirnotch(wo,bw);
x_notch = filtfilt(b_n,a_n,x_bp);
x = x(:);
t = (0:length(x)-1)’/Fs;
% Frequency analysis
x_dm = x – mean(x);
N = length(x_dm);
X = fft(x_dm);
K = floor(N/2);
X = X(1:K+1);
PSD = (1/(Fs*N)) * abs(X).^2;
if K > 1
PSD(2:end-1) = 2*PSD(2:end-1);
end
f = (0:K)’ * (Fs/N);
% Find dominant frequency
[~, idxPeak] = max(PSD(2:end)); % ignore 0 Hz
idxPeak = idxPeak + 1;
domFreq = f(idxPeak);
fprintf(‘Dominant frequency = %.2f Hzn’, domFreq);Which parts of this code is correct? I’m getting confused on which sections are relevant for my question above?
N = length(sig1);
xdft1 = fft(sig1);
xdft1 = xdft1(1:N/2+1);
psdx1 = (1/(Fs*N)) * abs(xdft1).^2;
psdx1(2:end-1) = 2*psdx1(2:end-1);
freq1 = 0:Fs/length(sig1):Fs/2;
P1_band = psdx1(freq1 >= 20 & freq1 <= 100);
f1_band = freq1(freq1 >= 20 & freq1 <= 100);
power_sig1 = trapz(f1_band, P1_band);
noise = x_new – x_notch;
SNR_dB = snr(x_notch, noise);
P_signal = mean(signalSeg.^2, ‘omitnan’);
P_noise = mean(noiseSeg.^2, ‘omitnan’);
SNR_dB = 10*log10(P_signal / P_noise);
f_notch = 60;
BW_notch = 2;
wo = f_notch/(Fs/2);
Q = f_notch/BW_notch;
bw = wo/Q;
[b_n,a_n] = iirnotch(wo,bw);
x_notch = filtfilt(b_n,a_n,x_bp);
x = x(:);
t = (0:length(x)-1)’/Fs;
% Frequency analysis
x_dm = x – mean(x);
N = length(x_dm);
X = fft(x_dm);
K = floor(N/2);
X = X(1:K+1);
PSD = (1/(Fs*N)) * abs(X).^2;
if K > 1
PSD(2:end-1) = 2*PSD(2:end-1);
end
f = (0:K)’ * (Fs/N);
% Find dominant frequency
[~, idxPeak] = max(PSD(2:end)); % ignore 0 Hz
idxPeak = idxPeak + 1;
domFreq = f(idxPeak);
fprintf(‘Dominant frequency = %.2f Hzn’, domFreq); Which parts of this code is correct? I’m getting confused on which sections are relevant for my question above?
N = length(sig1);
xdft1 = fft(sig1);
xdft1 = xdft1(1:N/2+1);
psdx1 = (1/(Fs*N)) * abs(xdft1).^2;
psdx1(2:end-1) = 2*psdx1(2:end-1);
freq1 = 0:Fs/length(sig1):Fs/2;
P1_band = psdx1(freq1 >= 20 & freq1 <= 100);
f1_band = freq1(freq1 >= 20 & freq1 <= 100);
power_sig1 = trapz(f1_band, P1_band);
noise = x_new – x_notch;
SNR_dB = snr(x_notch, noise);
P_signal = mean(signalSeg.^2, ‘omitnan’);
P_noise = mean(noiseSeg.^2, ‘omitnan’);
SNR_dB = 10*log10(P_signal / P_noise);
f_notch = 60;
BW_notch = 2;
wo = f_notch/(Fs/2);
Q = f_notch/BW_notch;
bw = wo/Q;
[b_n,a_n] = iirnotch(wo,bw);
x_notch = filtfilt(b_n,a_n,x_bp);
x = x(:);
t = (0:length(x)-1)’/Fs;
% Frequency analysis
x_dm = x – mean(x);
N = length(x_dm);
X = fft(x_dm);
K = floor(N/2);
X = X(1:K+1);
PSD = (1/(Fs*N)) * abs(X).^2;
if K > 1
PSD(2:end-1) = 2*PSD(2:end-1);
end
f = (0:K)’ * (Fs/N);
% Find dominant frequency
[~, idxPeak] = max(PSD(2:end)); % ignore 0 Hz
idxPeak = idxPeak + 1;
domFreq = f(idxPeak);
fprintf(‘Dominant frequency = %.2f Hzn’, domFreq); bandpower MATLAB Answers — New Questions
Need to download MATLAB 2008b onto my existing computer but no more activations exist for my license
My company (MITRE) has implemented CyberArk security that prevents me from accessing MATLAB on my C: drive. I needed to transfer MATLAB over to my personal folder but inorder to do this, I had to uninstall MATLAB. Unfortunately, when I try to reinstall MATLAB 2008b, it says I have no further activations on the license. This is the same computer that I have been using — I have not changed computers. I needed a similar license refresh a couple of years ago when a security breach resulted in scrubing the disk, prompting me to reinstall all of my former software including MATLAB. Please advise — I really rely on this software for my work.
Thank youMy company (MITRE) has implemented CyberArk security that prevents me from accessing MATLAB on my C: drive. I needed to transfer MATLAB over to my personal folder but inorder to do this, I had to uninstall MATLAB. Unfortunately, when I try to reinstall MATLAB 2008b, it says I have no further activations on the license. This is the same computer that I have been using — I have not changed computers. I needed a similar license refresh a couple of years ago when a security breach resulted in scrubing the disk, prompting me to reinstall all of my former software including MATLAB. Please advise — I really rely on this software for my work.
Thank you My company (MITRE) has implemented CyberArk security that prevents me from accessing MATLAB on my C: drive. I needed to transfer MATLAB over to my personal folder but inorder to do this, I had to uninstall MATLAB. Unfortunately, when I try to reinstall MATLAB 2008b, it says I have no further activations on the license. This is the same computer that I have been using — I have not changed computers. I needed a similar license refresh a couple of years ago when a security breach resulted in scrubing the disk, prompting me to reinstall all of my former software including MATLAB. Please advise — I really rely on this software for my work.
Thank you license activation MATLAB Answers — New Questions
proper IFFT procedure for converting S-params into time domain reflectometry
Basic discontinuety was simulated 0Hz to 40Ghz 40000 samples as presented in the photos . S-parameters were extracted as S2P file(attached in the link). My goal is to see the discontinuety using time domain reflectometry. what is the proper way to do IFFT in this case? What windows should I multiply with? Thanks.Basic discontinuety was simulated 0Hz to 40Ghz 40000 samples as presented in the photos . S-parameters were extracted as S2P file(attached in the link). My goal is to see the discontinuety using time domain reflectometry. what is the proper way to do IFFT in this case? What windows should I multiply with? Thanks. Basic discontinuety was simulated 0Hz to 40Ghz 40000 samples as presented in the photos . S-parameters were extracted as S2P file(attached in the link). My goal is to see the discontinuety using time domain reflectometry. what is the proper way to do IFFT in this case? What windows should I multiply with? Thanks. ifft, tdr, s-parameters MATLAB Answers — New Questions
Why Does polyval Return Zero When the Coefficients are Empty?
polyval([],1)
polyval(ones(1,0),1)
Do those results follow from a mathematical justification or are they arbitrarily specified?polyval([],1)
polyval(ones(1,0),1)
Do those results follow from a mathematical justification or are they arbitrarily specified? polyval([],1)
polyval(ones(1,0),1)
Do those results follow from a mathematical justification or are they arbitrarily specified? polynomial, empty coefficients MATLAB Answers — New Questions
I want to decrease the time my Script
Elapsed time is 8.597842 seconds.
clear, clc
tic
load(‘Erros_a.mat’); load(‘Sp1_b.mat’);
Relatorio = zeros(5000,4,’uint32′);
Relatorio_final = zeros(10000,4,’uint32′);
a = 10;
for i1 = 1:1
% BLOCO 1 — usa cache se existir, senão gera e salva
cache_file = sprintf(‘Erros_b_cache_%d.mat’, i1);
if exist(cache_file, ‘file’)
load(cache_file);
else
linha_a = Erros_a(a,:);
vals = linha_a(linha_a > 0);
vals = vals(1:end-2);
nRef = numel(vals);
cols_b1 = 2*(double(vals)-1) + 1;
cols_b2 = 2*(double(vals)-1) + 2;
passa = (Sp1_b(:, cols_b1) == 0) & (Sp1_b(:, cols_b2) == 0);
col_dest_matrix = uint32(cumsum(passa, 2) – passa + 1);
Erros_b = zeros(3268760, 37, ‘uint32’);
for d = 1:nRef
linhas_ok = find(passa(:, d));
if ~isempty(linhas_ok)
idx = sub2ind([3268760, 37], linhas_ok, double(col_dest_matrix(linhas_ok, d)));
Erros_b(idx) = vals(d);
end
end
save(cache_file, ‘Erros_b’, ‘-v7.3’);
end
% BLOCO 2 — preparação
load(‘Sp1_c.mat’);
Erros_b(:,38) = (1:size(Erros_b,1))’;
mascara = Erros_b(:, 13) > 50;
Erros_reduzido = Erros_b(mascara, :);
[lin_u, col_u] = find(Sp1_c == 1);
uns_nas_colunas = accumarray(col_u, lin_u, [size(Sp1_c,2) 1], @(x){sort(x)}, {[]});
clear Erros_b Sp1_c lin_u col_u mascara;
[~, ordem] = sortrows(Erros_reduzido(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido(ordem, :);
[~, ordem] = sortrows(Erros_reduzido_ordem(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido_ordem(ordem, :);
clear Erros_reduzido ordem;
ERO = double(Erros_reduzido_ordem);
clear Erros_reduzido_ordem;
nCols_c = numel(uns_nas_colunas);
uns_sets = cell(nCols_c, 1);
for cc = 1:nCols_c
s = uns_nas_colunas{cc};
if ~isempty(s)
m = false(max(s), 1);
m(s) = true;
uns_sets{cc} = m;
else
uns_sets{cc} = false(0,1);
end
end
% BLOCO 3 — while principal
num_linhas = size(ERO, 1);
y = 1;
offset = 0;
while (offset + 1) <= num_linhas
i = offset + 1;
linha_at = ERO(i, 1:38);
a_valid = linha_at(linha_at > 0 & linha_at <= 100);
% k=2: dois ponteiros
A = uns_nas_colunas{a_valid(1)};
B = uns_nas_colunas{a_valid(2)};
buf = zeros(min(numel(A), numel(B)), 1);
ia = 1; ib = 1; ic = 0;
na = numel(A); nb = numel(B);
while ia <= na && ib <= nb
if A(ia) == B(ib)
ic = ic + 1; buf(ic) = A(ia);
ia = ia + 1; ib = ib + 1;
elseif A(ia) < B(ib); ia = ia + 1;
else; ib = ib + 1;
end
end
candidatas = buf(1:ic);
w=1; z=1;
n(w,1) = a_valid(w,1);
achou = false;
if isempty(candidatas)
melhor_erro = a_valid(2) – 1;
melhor_linha = linha_at(38);
n(w,2) = a_valid(w,2);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = A(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
end
% k>=3: lookup lógico
for k = 3:length(a_valid)
if achou; break; end
n(w,k-1) = a_valid(w,k-1);
col_atual = a_valid(k);
s2 = uns_sets{col_atual};
if isempty(candidatas) || isempty(s2)
proximas = [];
else
mask = candidatas <= numel(s2);
cand_validas = candidatas(mask);
if isempty(cand_validas); proximas = [];
else; proximas = cand_validas(s2(cand_validas)); end
end
if isempty(proximas)
melhor_erro = col_atual – 1;
melhor_linha = linha_at(38);
n(w,k) = a_valid(w,k);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = candidatas(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
break;
end
candidatas = proximas;
melhor_linha = candidatas(1);
end % for k
if ~achou; offset = offset + 1; end
end % while
clear ERO uns_sets;
Relatorio = sortrows(Relatorio, 4, ‘descend’);
Relatorio_final(i1,:) = Relatorio(1,:);
Relatorio(:,:) = 0;
a = a + 1;
end % i1
tocElapsed time is 8.597842 seconds.
clear, clc
tic
load(‘Erros_a.mat’); load(‘Sp1_b.mat’);
Relatorio = zeros(5000,4,’uint32′);
Relatorio_final = zeros(10000,4,’uint32′);
a = 10;
for i1 = 1:1
% BLOCO 1 — usa cache se existir, senão gera e salva
cache_file = sprintf(‘Erros_b_cache_%d.mat’, i1);
if exist(cache_file, ‘file’)
load(cache_file);
else
linha_a = Erros_a(a,:);
vals = linha_a(linha_a > 0);
vals = vals(1:end-2);
nRef = numel(vals);
cols_b1 = 2*(double(vals)-1) + 1;
cols_b2 = 2*(double(vals)-1) + 2;
passa = (Sp1_b(:, cols_b1) == 0) & (Sp1_b(:, cols_b2) == 0);
col_dest_matrix = uint32(cumsum(passa, 2) – passa + 1);
Erros_b = zeros(3268760, 37, ‘uint32’);
for d = 1:nRef
linhas_ok = find(passa(:, d));
if ~isempty(linhas_ok)
idx = sub2ind([3268760, 37], linhas_ok, double(col_dest_matrix(linhas_ok, d)));
Erros_b(idx) = vals(d);
end
end
save(cache_file, ‘Erros_b’, ‘-v7.3’);
end
% BLOCO 2 — preparação
load(‘Sp1_c.mat’);
Erros_b(:,38) = (1:size(Erros_b,1))’;
mascara = Erros_b(:, 13) > 50;
Erros_reduzido = Erros_b(mascara, :);
[lin_u, col_u] = find(Sp1_c == 1);
uns_nas_colunas = accumarray(col_u, lin_u, [size(Sp1_c,2) 1], @(x){sort(x)}, {[]});
clear Erros_b Sp1_c lin_u col_u mascara;
[~, ordem] = sortrows(Erros_reduzido(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido(ordem, :);
[~, ordem] = sortrows(Erros_reduzido_ordem(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido_ordem(ordem, :);
clear Erros_reduzido ordem;
ERO = double(Erros_reduzido_ordem);
clear Erros_reduzido_ordem;
nCols_c = numel(uns_nas_colunas);
uns_sets = cell(nCols_c, 1);
for cc = 1:nCols_c
s = uns_nas_colunas{cc};
if ~isempty(s)
m = false(max(s), 1);
m(s) = true;
uns_sets{cc} = m;
else
uns_sets{cc} = false(0,1);
end
end
% BLOCO 3 — while principal
num_linhas = size(ERO, 1);
y = 1;
offset = 0;
while (offset + 1) <= num_linhas
i = offset + 1;
linha_at = ERO(i, 1:38);
a_valid = linha_at(linha_at > 0 & linha_at <= 100);
% k=2: dois ponteiros
A = uns_nas_colunas{a_valid(1)};
B = uns_nas_colunas{a_valid(2)};
buf = zeros(min(numel(A), numel(B)), 1);
ia = 1; ib = 1; ic = 0;
na = numel(A); nb = numel(B);
while ia <= na && ib <= nb
if A(ia) == B(ib)
ic = ic + 1; buf(ic) = A(ia);
ia = ia + 1; ib = ib + 1;
elseif A(ia) < B(ib); ia = ia + 1;
else; ib = ib + 1;
end
end
candidatas = buf(1:ic);
w=1; z=1;
n(w,1) = a_valid(w,1);
achou = false;
if isempty(candidatas)
melhor_erro = a_valid(2) – 1;
melhor_linha = linha_at(38);
n(w,2) = a_valid(w,2);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = A(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
end
% k>=3: lookup lógico
for k = 3:length(a_valid)
if achou; break; end
n(w,k-1) = a_valid(w,k-1);
col_atual = a_valid(k);
s2 = uns_sets{col_atual};
if isempty(candidatas) || isempty(s2)
proximas = [];
else
mask = candidatas <= numel(s2);
cand_validas = candidatas(mask);
if isempty(cand_validas); proximas = [];
else; proximas = cand_validas(s2(cand_validas)); end
end
if isempty(proximas)
melhor_erro = col_atual – 1;
melhor_linha = linha_at(38);
n(w,k) = a_valid(w,k);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = candidatas(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
break;
end
candidatas = proximas;
melhor_linha = candidatas(1);
end % for k
if ~achou; offset = offset + 1; end
end % while
clear ERO uns_sets;
Relatorio = sortrows(Relatorio, 4, ‘descend’);
Relatorio_final(i1,:) = Relatorio(1,:);
Relatorio(:,:) = 0;
a = a + 1;
end % i1
toc Elapsed time is 8.597842 seconds.
clear, clc
tic
load(‘Erros_a.mat’); load(‘Sp1_b.mat’);
Relatorio = zeros(5000,4,’uint32′);
Relatorio_final = zeros(10000,4,’uint32′);
a = 10;
for i1 = 1:1
% BLOCO 1 — usa cache se existir, senão gera e salva
cache_file = sprintf(‘Erros_b_cache_%d.mat’, i1);
if exist(cache_file, ‘file’)
load(cache_file);
else
linha_a = Erros_a(a,:);
vals = linha_a(linha_a > 0);
vals = vals(1:end-2);
nRef = numel(vals);
cols_b1 = 2*(double(vals)-1) + 1;
cols_b2 = 2*(double(vals)-1) + 2;
passa = (Sp1_b(:, cols_b1) == 0) & (Sp1_b(:, cols_b2) == 0);
col_dest_matrix = uint32(cumsum(passa, 2) – passa + 1);
Erros_b = zeros(3268760, 37, ‘uint32’);
for d = 1:nRef
linhas_ok = find(passa(:, d));
if ~isempty(linhas_ok)
idx = sub2ind([3268760, 37], linhas_ok, double(col_dest_matrix(linhas_ok, d)));
Erros_b(idx) = vals(d);
end
end
save(cache_file, ‘Erros_b’, ‘-v7.3’);
end
% BLOCO 2 — preparação
load(‘Sp1_c.mat’);
Erros_b(:,38) = (1:size(Erros_b,1))’;
mascara = Erros_b(:, 13) > 50;
Erros_reduzido = Erros_b(mascara, :);
[lin_u, col_u] = find(Sp1_c == 1);
uns_nas_colunas = accumarray(col_u, lin_u, [size(Sp1_c,2) 1], @(x){sort(x)}, {[]});
clear Erros_b Sp1_c lin_u col_u mascara;
[~, ordem] = sortrows(Erros_reduzido(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido(ordem, :);
[~, ordem] = sortrows(Erros_reduzido_ordem(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido_ordem(ordem, :);
clear Erros_reduzido ordem;
ERO = double(Erros_reduzido_ordem);
clear Erros_reduzido_ordem;
nCols_c = numel(uns_nas_colunas);
uns_sets = cell(nCols_c, 1);
for cc = 1:nCols_c
s = uns_nas_colunas{cc};
if ~isempty(s)
m = false(max(s), 1);
m(s) = true;
uns_sets{cc} = m;
else
uns_sets{cc} = false(0,1);
end
end
% BLOCO 3 — while principal
num_linhas = size(ERO, 1);
y = 1;
offset = 0;
while (offset + 1) <= num_linhas
i = offset + 1;
linha_at = ERO(i, 1:38);
a_valid = linha_at(linha_at > 0 & linha_at <= 100);
% k=2: dois ponteiros
A = uns_nas_colunas{a_valid(1)};
B = uns_nas_colunas{a_valid(2)};
buf = zeros(min(numel(A), numel(B)), 1);
ia = 1; ib = 1; ic = 0;
na = numel(A); nb = numel(B);
while ia <= na && ib <= nb
if A(ia) == B(ib)
ic = ic + 1; buf(ic) = A(ia);
ia = ia + 1; ib = ib + 1;
elseif A(ia) < B(ib); ia = ia + 1;
else; ib = ib + 1;
end
end
candidatas = buf(1:ic);
w=1; z=1;
n(w,1) = a_valid(w,1);
achou = false;
if isempty(candidatas)
melhor_erro = a_valid(2) – 1;
melhor_linha = linha_at(38);
n(w,2) = a_valid(w,2);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = A(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
end
% k>=3: lookup lógico
for k = 3:length(a_valid)
if achou; break; end
n(w,k-1) = a_valid(w,k-1);
col_atual = a_valid(k);
s2 = uns_sets{col_atual};
if isempty(candidatas) || isempty(s2)
proximas = [];
else
mask = candidatas <= numel(s2);
cand_validas = candidatas(mask);
if isempty(cand_validas); proximas = [];
else; proximas = cand_validas(s2(cand_validas)); end
end
if isempty(proximas)
melhor_erro = col_atual – 1;
melhor_linha = linha_at(38);
n(w,k) = a_valid(w,k);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = candidatas(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
break;
end
candidatas = proximas;
melhor_linha = candidatas(1);
end % for k
if ~achou; offset = offset + 1; end
end % while
clear ERO uns_sets;
Relatorio = sortrows(Relatorio, 4, ‘descend’);
Relatorio_final(i1,:) = Relatorio(1,:);
Relatorio(:,:) = 0;
a = a + 1;
end % i1
toc script slow MATLAB Answers — New Questions
Multithreding causing system crashes on linux
Hello,
Im trying to run a rather heavy calculation on our server, and high levels of multithreading causes the system to crash, sadly without crash log. The system does not respond to anything, both over the network and pressing the power button, and requires the power connection to be pulled before it can restart.
The linux version is "Ubunto 24.04.2 LTS", with two AMD EPYC 7763 64-Core Processor CPUs, about 1 TB of ram, a GeForce RTX 3050 8GB graphics card and a Supermicro H12DSi-NT6 mainboard.
When I use parpool and maxNumCompThreads at 16, the system works fine, but rather slow. At 32, the system works fine for a couple of minutes, before crashing, even when the CPU and Ram load never goes above 20%.
The computations include ffts, interpolation and complex to real and vice versa conversions.
Do you have any tips or hints where I can check what is happening, or do you have any information what is going on and what I can do to resolve this problem?
ThanksHello,
Im trying to run a rather heavy calculation on our server, and high levels of multithreading causes the system to crash, sadly without crash log. The system does not respond to anything, both over the network and pressing the power button, and requires the power connection to be pulled before it can restart.
The linux version is "Ubunto 24.04.2 LTS", with two AMD EPYC 7763 64-Core Processor CPUs, about 1 TB of ram, a GeForce RTX 3050 8GB graphics card and a Supermicro H12DSi-NT6 mainboard.
When I use parpool and maxNumCompThreads at 16, the system works fine, but rather slow. At 32, the system works fine for a couple of minutes, before crashing, even when the CPU and Ram load never goes above 20%.
The computations include ffts, interpolation and complex to real and vice versa conversions.
Do you have any tips or hints where I can check what is happening, or do you have any information what is going on and what I can do to resolve this problem?
Thanks Hello,
Im trying to run a rather heavy calculation on our server, and high levels of multithreading causes the system to crash, sadly without crash log. The system does not respond to anything, both over the network and pressing the power button, and requires the power connection to be pulled before it can restart.
The linux version is "Ubunto 24.04.2 LTS", with two AMD EPYC 7763 64-Core Processor CPUs, about 1 TB of ram, a GeForce RTX 3050 8GB graphics card and a Supermicro H12DSi-NT6 mainboard.
When I use parpool and maxNumCompThreads at 16, the system works fine, but rather slow. At 32, the system works fine for a couple of minutes, before crashing, even when the CPU and Ram load never goes above 20%.
The computations include ffts, interpolation and complex to real and vice versa conversions.
Do you have any tips or hints where I can check what is happening, or do you have any information what is going on and what I can do to resolve this problem?
Thanks parfor, multithreading, error, performance MATLAB Answers — New Questions
How to sign an .mlapp app packaged using MATLAB App designer?
Using Share to "Standalone Desktop App" in MATLAB App Designer, Is there a way to sign the installer .exe file that is generated, and also sign the application .exe file that is generated after the installation file is run? Currently, when using App Designer to package the app, it creates a build of the app and then packages it into an installation .exe file in the same workflow.
The issue I’m forseeing is that if I sign the installation .exe file, the application .exe file within will still be un-signed when it is generated after the installer is run. Am I right in thinking this? If so, is there a method of ensuring the application .exe file within is signed?Using Share to "Standalone Desktop App" in MATLAB App Designer, Is there a way to sign the installer .exe file that is generated, and also sign the application .exe file that is generated after the installation file is run? Currently, when using App Designer to package the app, it creates a build of the app and then packages it into an installation .exe file in the same workflow.
The issue I’m forseeing is that if I sign the installation .exe file, the application .exe file within will still be un-signed when it is generated after the installer is run. Am I right in thinking this? If so, is there a method of ensuring the application .exe file within is signed? Using Share to "Standalone Desktop App" in MATLAB App Designer, Is there a way to sign the installer .exe file that is generated, and also sign the application .exe file that is generated after the installation file is run? Currently, when using App Designer to package the app, it creates a build of the app and then packages it into an installation .exe file in the same workflow.
The issue I’m forseeing is that if I sign the installation .exe file, the application .exe file within will still be un-signed when it is generated after the installer is run. Am I right in thinking this? If so, is there a method of ensuring the application .exe file within is signed? app designer, compiler, certificate, signing MATLAB Answers — New Questions
“operation not allowed” when accessing network drive
I get an "operation not allowed" error in Matlab (only in Matlab) on MacOS when trying to access network-mounted RAID drive
Desktop Mac (1) running Macos 26.3.1, has network-mounted a USB-C external RAID drive connected to older desktop Mac (2) running 15.7.4.
I can view, edit, save etc. files on the (remote) RAID system using terminal windows on (1), using Finder, TextEdit, etc.. But attempting to access folders or files from within Matlab R2024b returns the error "operation not allowed".
Both systems (1) & (2) have Matlab given "full disk access" in Settings>Privacy&Security>FullDiskAccess. Both systems have user given read&write access for shared network drive in Finder>Get_Info, in Unix permissions, and in Settings>Sharing>File_Sharing.
Matlab on (2) can read & write files on the (locally-attached) RAID drive. The problem is only when trying to access the RAID drive from within in Matlab on (1).
smbd also has full disk access (as is clear since terminal and other apps can read & write RAID drive over network connection).
Any suggestions would be appreciated.I get an "operation not allowed" error in Matlab (only in Matlab) on MacOS when trying to access network-mounted RAID drive
Desktop Mac (1) running Macos 26.3.1, has network-mounted a USB-C external RAID drive connected to older desktop Mac (2) running 15.7.4.
I can view, edit, save etc. files on the (remote) RAID system using terminal windows on (1), using Finder, TextEdit, etc.. But attempting to access folders or files from within Matlab R2024b returns the error "operation not allowed".
Both systems (1) & (2) have Matlab given "full disk access" in Settings>Privacy&Security>FullDiskAccess. Both systems have user given read&write access for shared network drive in Finder>Get_Info, in Unix permissions, and in Settings>Sharing>File_Sharing.
Matlab on (2) can read & write files on the (locally-attached) RAID drive. The problem is only when trying to access the RAID drive from within in Matlab on (1).
smbd also has full disk access (as is clear since terminal and other apps can read & write RAID drive over network connection).
Any suggestions would be appreciated. I get an "operation not allowed" error in Matlab (only in Matlab) on MacOS when trying to access network-mounted RAID drive
Desktop Mac (1) running Macos 26.3.1, has network-mounted a USB-C external RAID drive connected to older desktop Mac (2) running 15.7.4.
I can view, edit, save etc. files on the (remote) RAID system using terminal windows on (1), using Finder, TextEdit, etc.. But attempting to access folders or files from within Matlab R2024b returns the error "operation not allowed".
Both systems (1) & (2) have Matlab given "full disk access" in Settings>Privacy&Security>FullDiskAccess. Both systems have user given read&write access for shared network drive in Finder>Get_Info, in Unix permissions, and in Settings>Sharing>File_Sharing.
Matlab on (2) can read & write files on the (locally-attached) RAID drive. The problem is only when trying to access the RAID drive from within in Matlab on (1).
smbd also has full disk access (as is clear since terminal and other apps can read & write RAID drive over network connection).
Any suggestions would be appreciated. operation not allowed MATLAB Answers — New Questions
How do I determine the linear part of a force-displacement curve?
I have a force-displacement graph (the attached file) and I want to find out exactly at what point the linear portion of the graph ends. Please see the picture for more clarification.
I’ve already smoothed out the curve, so it is noiseless.
I did a quick search but couldn’t find anything useful.
Any help would be highly appreciated.I have a force-displacement graph (the attached file) and I want to find out exactly at what point the linear portion of the graph ends. Please see the picture for more clarification.
I’ve already smoothed out the curve, so it is noiseless.
I did a quick search but couldn’t find anything useful.
Any help would be highly appreciated. I have a force-displacement graph (the attached file) and I want to find out exactly at what point the linear portion of the graph ends. Please see the picture for more clarification.
I’ve already smoothed out the curve, so it is noiseless.
I did a quick search but couldn’t find anything useful.
Any help would be highly appreciated. linear part, nonlinear part MATLAB Answers — New Questions
Best way to relabel axis as pi for trig functions.
Hi all, I was looking for ways to relabel my x-axis as pi increments for trig functions and was wondering which one would be most effective.
This is what chatgpt gave, but I wanted to see if there are any better ways to achieve the same result. TIA!!
clc, clearvars
x = linspace(0,2*pi,200);
y = sin(x);
% Plot
figure
hold on
plot(x, y)
% Pi Labeling
xt = 0:pi/2:2*pi;
xticks(xt)
label = compose(‘%g\pi’, xt/pi);
xticklabels(label)Hi all, I was looking for ways to relabel my x-axis as pi increments for trig functions and was wondering which one would be most effective.
This is what chatgpt gave, but I wanted to see if there are any better ways to achieve the same result. TIA!!
clc, clearvars
x = linspace(0,2*pi,200);
y = sin(x);
% Plot
figure
hold on
plot(x, y)
% Pi Labeling
xt = 0:pi/2:2*pi;
xticks(xt)
label = compose(‘%g\pi’, xt/pi);
xticklabels(label) Hi all, I was looking for ways to relabel my x-axis as pi increments for trig functions and was wondering which one would be most effective.
This is what chatgpt gave, but I wanted to see if there are any better ways to achieve the same result. TIA!!
clc, clearvars
x = linspace(0,2*pi,200);
y = sin(x);
% Plot
figure
hold on
plot(x, y)
% Pi Labeling
xt = 0:pi/2:2*pi;
xticks(xt)
label = compose(‘%g\pi’, xt/pi);
xticklabels(label) xtick, label, trigonometry, pi MATLAB Answers — New Questions
Probléme sur mon programme matlab avec la fonction lsqcurvefit
Bonjour la communauté,
enfaite présentatement je travail sur un programme qui permets de recueillir les paramétre du modèle de Cole_cole à partir des mesures que j’ai eu. Donc l’idéé c’est de faire un programme qui va tracer une courbe qui se superpose à la mesure et me donner les paramétre du modèle correspondant. là j’utilise le lsqcurvefit mais le programme me retourne les valeurs d’initialisation et je sais pas ca peut être dû quoi ?
Merci d’avance de votre réponseBonjour la communauté,
enfaite présentatement je travail sur un programme qui permets de recueillir les paramétre du modèle de Cole_cole à partir des mesures que j’ai eu. Donc l’idéé c’est de faire un programme qui va tracer une courbe qui se superpose à la mesure et me donner les paramétre du modèle correspondant. là j’utilise le lsqcurvefit mais le programme me retourne les valeurs d’initialisation et je sais pas ca peut être dû quoi ?
Merci d’avance de votre réponse Bonjour la communauté,
enfaite présentatement je travail sur un programme qui permets de recueillir les paramétre du modèle de Cole_cole à partir des mesures que j’ai eu. Donc l’idéé c’est de faire un programme qui va tracer une courbe qui se superpose à la mesure et me donner les paramétre du modèle correspondant. là j’utilise le lsqcurvefit mais le programme me retourne les valeurs d’initialisation et je sais pas ca peut être dû quoi ?
Merci d’avance de votre réponse mbengue MATLAB Answers — New Questions
“Index exceeds 37” when 35 variables?
So, I’ve been trying to do 3 variable modeling in MATLAB. I have four sets of data (3 variables and one answer), and I’m trying to bet an equation modeling the data. When running the section of the code pasted below, I keep getting "Index exceeds number of array elements. Index must not exceed 37". There are only 35 variables in the code, so I’m not sure why this isn’t working. As far as why I chose this format, I think x and z can be modeled by a quadratic individually, but I figured each variable needed to be the same power, so they’re all 4th power. Any help would be greatly appreciated.
ft = fittype([ …
‘p000 + p100*x + p010*y + p001*z + ‘ …
‘p200*x.^2 + p020*y.^2 + p002*z.^2 + ‘ …
‘p110*x*y + p101*x*z + p011*y*z + ‘ …
‘p300*x.^3 + p030*y.^3 + p003*z.^3 + ‘ …
‘p210*x.^2*y + p201*x.^2*z + p120*x*y.^2 + ‘ …
‘p021*y.^2*z + p102*x*z.^2 + p012*y*z.^2 + ‘ …
‘p111*x*y*z + ‘ …
‘p400*x.^4 + p040*y.^4 + p004*z.^4 + ‘ …
‘p310*x.^3*y + p301*x.^3*z + p130*x*y.^3 + ‘ …
‘p031*y.^3*z + p103*x*z.^3 + p013*y*z.^3 + ‘ …
‘p220*x.^2*y.^2 + p202*x.^2*z.^2 + p022*y.^2*z.^2 + ‘ …
‘p211*x.^2*y*z + p121*x*y.^2*z + p112*x*y*z.^2’], …
‘independent’, {‘x’, ‘y’, ‘z’}, …
‘dependent’, ‘v’);
[fitobject, gof, output] = fit([x, y, z], v, ft);
disp(fitobject)So, I’ve been trying to do 3 variable modeling in MATLAB. I have four sets of data (3 variables and one answer), and I’m trying to bet an equation modeling the data. When running the section of the code pasted below, I keep getting "Index exceeds number of array elements. Index must not exceed 37". There are only 35 variables in the code, so I’m not sure why this isn’t working. As far as why I chose this format, I think x and z can be modeled by a quadratic individually, but I figured each variable needed to be the same power, so they’re all 4th power. Any help would be greatly appreciated.
ft = fittype([ …
‘p000 + p100*x + p010*y + p001*z + ‘ …
‘p200*x.^2 + p020*y.^2 + p002*z.^2 + ‘ …
‘p110*x*y + p101*x*z + p011*y*z + ‘ …
‘p300*x.^3 + p030*y.^3 + p003*z.^3 + ‘ …
‘p210*x.^2*y + p201*x.^2*z + p120*x*y.^2 + ‘ …
‘p021*y.^2*z + p102*x*z.^2 + p012*y*z.^2 + ‘ …
‘p111*x*y*z + ‘ …
‘p400*x.^4 + p040*y.^4 + p004*z.^4 + ‘ …
‘p310*x.^3*y + p301*x.^3*z + p130*x*y.^3 + ‘ …
‘p031*y.^3*z + p103*x*z.^3 + p013*y*z.^3 + ‘ …
‘p220*x.^2*y.^2 + p202*x.^2*z.^2 + p022*y.^2*z.^2 + ‘ …
‘p211*x.^2*y*z + p121*x*y.^2*z + p112*x*y*z.^2’], …
‘independent’, {‘x’, ‘y’, ‘z’}, …
‘dependent’, ‘v’);
[fitobject, gof, output] = fit([x, y, z], v, ft);
disp(fitobject) So, I’ve been trying to do 3 variable modeling in MATLAB. I have four sets of data (3 variables and one answer), and I’m trying to bet an equation modeling the data. When running the section of the code pasted below, I keep getting "Index exceeds number of array elements. Index must not exceed 37". There are only 35 variables in the code, so I’m not sure why this isn’t working. As far as why I chose this format, I think x and z can be modeled by a quadratic individually, but I figured each variable needed to be the same power, so they’re all 4th power. Any help would be greatly appreciated.
ft = fittype([ …
‘p000 + p100*x + p010*y + p001*z + ‘ …
‘p200*x.^2 + p020*y.^2 + p002*z.^2 + ‘ …
‘p110*x*y + p101*x*z + p011*y*z + ‘ …
‘p300*x.^3 + p030*y.^3 + p003*z.^3 + ‘ …
‘p210*x.^2*y + p201*x.^2*z + p120*x*y.^2 + ‘ …
‘p021*y.^2*z + p102*x*z.^2 + p012*y*z.^2 + ‘ …
‘p111*x*y*z + ‘ …
‘p400*x.^4 + p040*y.^4 + p004*z.^4 + ‘ …
‘p310*x.^3*y + p301*x.^3*z + p130*x*y.^3 + ‘ …
‘p031*y.^3*z + p103*x*z.^3 + p013*y*z.^3 + ‘ …
‘p220*x.^2*y.^2 + p202*x.^2*z.^2 + p022*y.^2*z.^2 + ‘ …
‘p211*x.^2*y*z + p121*x*y.^2*z + p112*x*y*z.^2’], …
‘independent’, {‘x’, ‘y’, ‘z’}, …
‘dependent’, ‘v’);
[fitobject, gof, output] = fit([x, y, z], v, ft);
disp(fitobject) error, curve fitting MATLAB Answers — New Questions
How to use AI to edit UI of app using AppDesigner
We are building an app with AppDesigner (24b currently). To get help designing we are using AI features. The suggestions seem good, and I want to adapt my AppDesigner Code. However, the code of the UI is greyed out. Secondly, unzipping the .mlapp and editing the matlab/document.xml does not work, as zipping again creates an not running (and smaller in size) .mlapp file. Is there a way to get access to the UI Code and to edit it effectively? Thank you.We are building an app with AppDesigner (24b currently). To get help designing we are using AI features. The suggestions seem good, and I want to adapt my AppDesigner Code. However, the code of the UI is greyed out. Secondly, unzipping the .mlapp and editing the matlab/document.xml does not work, as zipping again creates an not running (and smaller in size) .mlapp file. Is there a way to get access to the UI Code and to edit it effectively? Thank you. We are building an app with AppDesigner (24b currently). To get help designing we are using AI features. The suggestions seem good, and I want to adapt my AppDesigner Code. However, the code of the UI is greyed out. Secondly, unzipping the .mlapp and editing the matlab/document.xml does not work, as zipping again creates an not running (and smaller in size) .mlapp file. Is there a way to get access to the UI Code and to edit it effectively? Thank you. appdesigner, ai MATLAB Answers — New Questions
Why is Jaaba stuck open on MATLAB online?
I was trying to run JAABA and realized I don’t have the correct video file format yet, but when I tried to exit out of the dialog box that comes up it is completely frozen. I can’t type or select anything in matlab online and even when I close out of it and reopen the dialog box is still stuck there. Thank you!I was trying to run JAABA and realized I don’t have the correct video file format yet, but when I tried to exit out of the dialog box that comes up it is completely frozen. I can’t type or select anything in matlab online and even when I close out of it and reopen the dialog box is still stuck there. Thank you! I was trying to run JAABA and realized I don’t have the correct video file format yet, but when I tried to exit out of the dialog box that comes up it is completely frozen. I can’t type or select anything in matlab online and even when I close out of it and reopen the dialog box is still stuck there. Thank you! jaaba, frozen, stuck MATLAB Answers — New Questions
How do I install additional toolboxes into an existing installation of MATLAB?
New toolboxes have just been added to my license. How do I install additional toolboxes into an existing installation of MATLAB?New toolboxes have just been added to my license. How do I install additional toolboxes into an existing installation of MATLAB? New toolboxes have just been added to my license. How do I install additional toolboxes into an existing installation of MATLAB? MATLAB Answers — New Questions
Undefined function ‘imhistc’ for input arguments of type ‘uint8’.
Im trying to get the histogram of an image using imhist. however its showing the above error? i tried which imhistc and its not found. Im using matlab R2016Im trying to get the histogram of an image using imhist. however its showing the above error? i tried which imhistc and its not found. Im using matlab R2016 Im trying to get the histogram of an image using imhist. however its showing the above error? i tried which imhistc and its not found. Im using matlab R2016 matlab, histogram MATLAB Answers — New Questions
Kinks/discontinuities in pdepe solution
Hello everyone,
I’ve been working with Matlab pdepe to solve numerically a set of coupled partial differential equations. I’m fairly new and I’ve encountered a problem with the numerical solution that I get from my code and can’t seem to get rid of it. The equations model the diffusion and decay of two species in a material over 100s of ns. The problem I’m getting is that when I look at the solution in a log time scale, several kinks appear. Here are different things I’ve tried and haven’t helped:
Make tspan finer. (30-1000 points)
Make xmesh finer. (50-1000 points)
Increase or decrease relative tolerance (1E0 to 1E-6).
Make tspan time separation linear after t = 0.
Make tspan time separation increase logarithmically after t = 0.1 s
Any insights into how I could solve the problem would be useful.
% Physical constants
%params = [DR TR TT A B];
DR_guess = 1E6; % in nm^2 /ns
DT_guess = 1E1; % in nm^2 /ns
TR_guess = 14; % in ns
TT_guess = 130; % in ns
T0 = 295; % in K
R0 = 0.016;% in e/nm^3
A = 1;
B = 200;
Y = 0.3056;
CR = -80000;
CT = 220;
params = [DR_guess DT_guess TR_guess TT_guess T0 R0 A B Y CR CT];
% Setting up the mesh for space and time
xmesh = linspace(0,2000,55); %in nm
tspan = [-5, -2, -1, -0.5, 0, logspace(-1, 3, 80)];% in ns
% Solving the differential equation
options = odeset(‘RelTol’,1e-0,’OutputFcn’,@myOut,’Stats’,’on’);
pde = @(x, t, u, dudx) AgSepde(x, t, u, dudx, params);
soln = pdepe(1, pde, @AgSeic, @AgSebc, xmesh, tspan, options);
% Partial differential equation function
function [c,f,s] = AgSepde(x,t,u,dudx,params)
% Parameters for PDEs
DR = params(1);
DT = params(2);
TR = params(3);
TT = params(4);
T0 = params(5);
R0 = params(6);
A = params(7);
B = params(8);
Y = params(9);
% Generation function
sigmar = 180; % in nm
sigmat = 0.2; %in ns
t0 = 0.00; % in ns
G = (1 / (sigmar * sqrt(2*pi))) * exp(-x.^2 / (2 * sigmar^2)) …
* (1 / (sigmat * sqrt(2*pi))) * exp(-(t – t0).^2 / (2 * sigmat^2));
c = [1; 1];
f = [DR*dudx(1); DT*dudx(2)];
s = [-(u(1) – R0)/TR + A*G; Y*(u(1)- R0) – (u(2) – T0)/TT + B*G];
end
% Intial conditions for the PDEs
function u0 = AgSeic(x)
T0 = 295;
R0 = 0.016;
u0 = [R0; T0];
end
function [pl, ql, pr, qr] = AgSebc(xl, ul, xr, ur, t)
% Left boundary: u(0,t) = 1
pl = [0; 0];
ql = [1; 1];
% Right boundary: u(x’,t) = 0
pr = [0; 0];
qr = [1; 1];
end
function status = myOut(t,y,flag)
persistent last
if strcmp(flag,’init’), last = tic; end
if isempty(flag) && toc(last) > 1
fprintf(‘t = %.3g nsn’, t(end));
last = tic;
end
status = 0;
end
%% Figures
tiledlayout(2,1)
nexttile(1,[1,1])
hold on;
plot(tspan,soln(:,1,1),’Marker’,’o’);
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 1’);
hold off;
nexttile(2,[1,1])
hold on;
plot(tspan,soln(:,1,2),’Marker’,’square’)
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 2’);
hold off;Hello everyone,
I’ve been working with Matlab pdepe to solve numerically a set of coupled partial differential equations. I’m fairly new and I’ve encountered a problem with the numerical solution that I get from my code and can’t seem to get rid of it. The equations model the diffusion and decay of two species in a material over 100s of ns. The problem I’m getting is that when I look at the solution in a log time scale, several kinks appear. Here are different things I’ve tried and haven’t helped:
Make tspan finer. (30-1000 points)
Make xmesh finer. (50-1000 points)
Increase or decrease relative tolerance (1E0 to 1E-6).
Make tspan time separation linear after t = 0.
Make tspan time separation increase logarithmically after t = 0.1 s
Any insights into how I could solve the problem would be useful.
% Physical constants
%params = [DR TR TT A B];
DR_guess = 1E6; % in nm^2 /ns
DT_guess = 1E1; % in nm^2 /ns
TR_guess = 14; % in ns
TT_guess = 130; % in ns
T0 = 295; % in K
R0 = 0.016;% in e/nm^3
A = 1;
B = 200;
Y = 0.3056;
CR = -80000;
CT = 220;
params = [DR_guess DT_guess TR_guess TT_guess T0 R0 A B Y CR CT];
% Setting up the mesh for space and time
xmesh = linspace(0,2000,55); %in nm
tspan = [-5, -2, -1, -0.5, 0, logspace(-1, 3, 80)];% in ns
% Solving the differential equation
options = odeset(‘RelTol’,1e-0,’OutputFcn’,@myOut,’Stats’,’on’);
pde = @(x, t, u, dudx) AgSepde(x, t, u, dudx, params);
soln = pdepe(1, pde, @AgSeic, @AgSebc, xmesh, tspan, options);
% Partial differential equation function
function [c,f,s] = AgSepde(x,t,u,dudx,params)
% Parameters for PDEs
DR = params(1);
DT = params(2);
TR = params(3);
TT = params(4);
T0 = params(5);
R0 = params(6);
A = params(7);
B = params(8);
Y = params(9);
% Generation function
sigmar = 180; % in nm
sigmat = 0.2; %in ns
t0 = 0.00; % in ns
G = (1 / (sigmar * sqrt(2*pi))) * exp(-x.^2 / (2 * sigmar^2)) …
* (1 / (sigmat * sqrt(2*pi))) * exp(-(t – t0).^2 / (2 * sigmat^2));
c = [1; 1];
f = [DR*dudx(1); DT*dudx(2)];
s = [-(u(1) – R0)/TR + A*G; Y*(u(1)- R0) – (u(2) – T0)/TT + B*G];
end
% Intial conditions for the PDEs
function u0 = AgSeic(x)
T0 = 295;
R0 = 0.016;
u0 = [R0; T0];
end
function [pl, ql, pr, qr] = AgSebc(xl, ul, xr, ur, t)
% Left boundary: u(0,t) = 1
pl = [0; 0];
ql = [1; 1];
% Right boundary: u(x’,t) = 0
pr = [0; 0];
qr = [1; 1];
end
function status = myOut(t,y,flag)
persistent last
if strcmp(flag,’init’), last = tic; end
if isempty(flag) && toc(last) > 1
fprintf(‘t = %.3g nsn’, t(end));
last = tic;
end
status = 0;
end
%% Figures
tiledlayout(2,1)
nexttile(1,[1,1])
hold on;
plot(tspan,soln(:,1,1),’Marker’,’o’);
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 1’);
hold off;
nexttile(2,[1,1])
hold on;
plot(tspan,soln(:,1,2),’Marker’,’square’)
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 2’);
hold off; Hello everyone,
I’ve been working with Matlab pdepe to solve numerically a set of coupled partial differential equations. I’m fairly new and I’ve encountered a problem with the numerical solution that I get from my code and can’t seem to get rid of it. The equations model the diffusion and decay of two species in a material over 100s of ns. The problem I’m getting is that when I look at the solution in a log time scale, several kinks appear. Here are different things I’ve tried and haven’t helped:
Make tspan finer. (30-1000 points)
Make xmesh finer. (50-1000 points)
Increase or decrease relative tolerance (1E0 to 1E-6).
Make tspan time separation linear after t = 0.
Make tspan time separation increase logarithmically after t = 0.1 s
Any insights into how I could solve the problem would be useful.
% Physical constants
%params = [DR TR TT A B];
DR_guess = 1E6; % in nm^2 /ns
DT_guess = 1E1; % in nm^2 /ns
TR_guess = 14; % in ns
TT_guess = 130; % in ns
T0 = 295; % in K
R0 = 0.016;% in e/nm^3
A = 1;
B = 200;
Y = 0.3056;
CR = -80000;
CT = 220;
params = [DR_guess DT_guess TR_guess TT_guess T0 R0 A B Y CR CT];
% Setting up the mesh for space and time
xmesh = linspace(0,2000,55); %in nm
tspan = [-5, -2, -1, -0.5, 0, logspace(-1, 3, 80)];% in ns
% Solving the differential equation
options = odeset(‘RelTol’,1e-0,’OutputFcn’,@myOut,’Stats’,’on’);
pde = @(x, t, u, dudx) AgSepde(x, t, u, dudx, params);
soln = pdepe(1, pde, @AgSeic, @AgSebc, xmesh, tspan, options);
% Partial differential equation function
function [c,f,s] = AgSepde(x,t,u,dudx,params)
% Parameters for PDEs
DR = params(1);
DT = params(2);
TR = params(3);
TT = params(4);
T0 = params(5);
R0 = params(6);
A = params(7);
B = params(8);
Y = params(9);
% Generation function
sigmar = 180; % in nm
sigmat = 0.2; %in ns
t0 = 0.00; % in ns
G = (1 / (sigmar * sqrt(2*pi))) * exp(-x.^2 / (2 * sigmar^2)) …
* (1 / (sigmat * sqrt(2*pi))) * exp(-(t – t0).^2 / (2 * sigmat^2));
c = [1; 1];
f = [DR*dudx(1); DT*dudx(2)];
s = [-(u(1) – R0)/TR + A*G; Y*(u(1)- R0) – (u(2) – T0)/TT + B*G];
end
% Intial conditions for the PDEs
function u0 = AgSeic(x)
T0 = 295;
R0 = 0.016;
u0 = [R0; T0];
end
function [pl, ql, pr, qr] = AgSebc(xl, ul, xr, ur, t)
% Left boundary: u(0,t) = 1
pl = [0; 0];
ql = [1; 1];
% Right boundary: u(x’,t) = 0
pr = [0; 0];
qr = [1; 1];
end
function status = myOut(t,y,flag)
persistent last
if strcmp(flag,’init’), last = tic; end
if isempty(flag) && toc(last) > 1
fprintf(‘t = %.3g nsn’, t(end));
last = tic;
end
status = 0;
end
%% Figures
tiledlayout(2,1)
nexttile(1,[1,1])
hold on;
plot(tspan,soln(:,1,1),’Marker’,’o’);
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 1’);
hold off;
nexttile(2,[1,1])
hold on;
plot(tspan,soln(:,1,2),’Marker’,’square’)
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 2’);
hold off; pde, pdepe MATLAB Answers — New Questions
Question about loading multiple files
Greetings,
I wrote an ‘m’ function to load several files recursively and do some processing/graphing.
If I declare the file names in a string array, then the code executes with no issue.
However, if I load all files with the dir() function, I get an error message after the 1st file is loaded. What am I missing?
DIR_STR=dir(‘*.mf4’);
FILES= DIR_STR.name
for ii=1:5
FILE=FILES(ii,:)
disp([‘ii = ‘ num2str(ii) ‘ — File: ‘ FILE])
endGreetings,
I wrote an ‘m’ function to load several files recursively and do some processing/graphing.
If I declare the file names in a string array, then the code executes with no issue.
However, if I load all files with the dir() function, I get an error message after the 1st file is loaded. What am I missing?
DIR_STR=dir(‘*.mf4’);
FILES= DIR_STR.name
for ii=1:5
FILE=FILES(ii,:)
disp([‘ii = ‘ num2str(ii) ‘ — File: ‘ FILE])
end Greetings,
I wrote an ‘m’ function to load several files recursively and do some processing/graphing.
If I declare the file names in a string array, then the code executes with no issue.
However, if I load all files with the dir() function, I get an error message after the 1st file is loaded. What am I missing?
DIR_STR=dir(‘*.mf4’);
FILES= DIR_STR.name
for ii=1:5
FILE=FILES(ii,:)
disp([‘ii = ‘ num2str(ii) ‘ — File: ‘ FILE])
end loading multiple files MATLAB Answers — New Questions
Simulink Multiplatform Code Generation
I use a FMU inside a Simulink model from which I want to generate code, how could I generate multiplatform code of this Simulink model including the FMU? For example for Linux and CPU ARM.
Thank you very much in advance.
Best regards,
Víctor Sánchez SuárezI use a FMU inside a Simulink model from which I want to generate code, how could I generate multiplatform code of this Simulink model including the FMU? For example for Linux and CPU ARM.
Thank you very much in advance.
Best regards,
Víctor Sánchez Suárez I use a FMU inside a Simulink model from which I want to generate code, how could I generate multiplatform code of this Simulink model including the FMU? For example for Linux and CPU ARM.
Thank you very much in advance.
Best regards,
Víctor Sánchez Suárez code generation, simulink, fmu MATLAB Answers — New Questions
guidance on code structure improvement
I would like to know if this code can be improved/optimized. is it well-written? Any help will be appreciated. Thanks
function main_solver_optimized()
params.alpha = 0.04; params.beta = 1e4; params.gamma = 3e7;
y0 = [1; 0; 0];
tspan = [0, 1e6];
h0 = 1e-4;
tol = 1e-2;
fprintf(‘Running Part 1: Radau IIA (2-stage vs 3-stage)…n’);
[T1, Y1, s1, r1] = solve_robertson(y0, tspan, h0, tol, params, ‘Radau’);
fprintf(‘Running Part 2: SDIRK 3(4)…n’);
[T2, Y2, s2, r2] = solve_robertson(y0, tspan, h0, tol, params, ‘SDIRK’);
fprintf(‘n================ RESULTS COMPARISON ================n’);
fprintf(‘Method | Successful Steps | Rejected Stepsn’);
fprintf(‘—————————————————-n’);
fprintf(‘Radau IIA | %16d | %14dn’, s1, r1);
fprintf(‘SDIRK 3(4) | %16d | %14dn’, s2, r2);
fprintf(‘====================================================n’);
figure(‘Name’, ‘Robertson Problem Solutions’);
subplot(2,1,1);
semilogx(T1, Y1(:,1), T1, Y1(:,2)*1e4, T1, Y1(:,3), ‘LineWidth’, 1.5);
title(‘Part 1: Radau IIA Method’); xlabel(‘Time (s)’); ylabel(‘Concentration’);
legend(‘y_1’, ‘y_2 times 10^4’, ‘y_3’, ‘Location’, ‘Best’); grid on;
subplot(2,1,2);
semilogx(T2, Y2(:,1), T2, Y2(:,2)*1e4, T2, Y2(:,3), ‘LineWidth’, 1.5);
title(‘Part 2: SDIRK 3(4) Method’); xlabel(‘Time (s)’); ylabel(‘Concentration’);
legend(‘y_1’, ‘y_2 times 10^4’, ‘y_3’, ‘Location’, ‘Best’); grid on;
end
function [T, Y, success, rejected] = solve_robertson(y0, tspan, h, tol, p, method)
Nmax = 1e6;
T = zeros(Nmax,1); Y = zeros(Nmax,3);
t = tspan(1); y = y0;
T(1) = t; Y(1,:) = y’;
stepCount = 1;
success = 0; rejected = 0;
if strcmp(method,’Radau’)
A2 = [5/12, -1/12; 3/4, 1/4]; c2 = [1/3, 1]’;
sq6 = sqrt(6);
A3 = [(88-7*sq6)/360, (296-169*sq6)/1800, (-2+3*sq6)/225; …
(296+169*sq6)/1800, (88+7*sq6)/360, (-2-3*sq6)/225; …
(16-sq6)/36, (16+sq6)/36, 1/9];
c3 = [(4-sq6)/10, (4+sq6)/10, 1]’;
solver_func = @(y,h) solve_radau_adaptive(y,h,A2,c2,A3,c3,p);
order_p = 3;
else
gam = 1/4;
A = [gam, 0, 0, 0, 0;
1/2-gam, gam, 0, 0, 0;
2*gam, 1-4*gam, gam, 0, 0;
1/10, 1/10, 1/10+gam, gam, 0;
1/4, 1/4, 0, 1/4, gam];
c = [1/4, 3/4, 11/20, 1/2, 1]’;
b = [1/4, 1/4, 0, 1/4, 1/4];
bhat = [-3/16, 5/8, 3/16, 1/16, 5/16];
solver_func = @(y,h) solve_sdirk_sequential(y,h,A,b,bhat,c,p);
order_p = 3;
end
while t < tspan(2)
if t + h > tspan(2), h = tspan(2) – t; end
[y_n, y_hat, converged] = solver_func(y,h);
if converged
err = max(abs(y_n – y_hat));
if err <= tol
t = t + h; y = y_n;
stepCount = stepCount + 1;
T(stepCount) = t;
Y(stepCount,:) = y’;
success = success + 1;
h = h * min(5, max(0.1, 0.9*(tol/err)^(1/(order_p+1))));
else
h = h/4; rejected = rejected + 1;
end
else
h = h/4; rejected = rejected + 1;
end
end
T = T(1:stepCount); Y = Y(1:stepCount,:);
end
function [ynext, yhat, conv] = solve_radau_adaptive(y, h, A2, c2, A3, c3, p)
ynext = y + 0;
yhat = y + 0;
conv = true;
end
function [ynext, yhat, conv] = solve_sdirk_sequential(y, h, A, b, bhat, c, p)
s = length(c);
K = zeros(3,s);
conv = true;
for i = 1:s
ki = zeros(3,1);
rhs = y + h*(K(:,1:i-1)*A(i,1:i-1)’);
for iter = 1:5
val = rhs + h*A(i,i)*ki;
f_val = [-p.alpha*val(1) + p.beta*val(2)*val(3); …
p.alpha*val(1) – p.beta*val(2)*val(3) – p.gamma*val(2)^2; …
p.gamma*val(2)^2];
jac = [-p.alpha, p.beta*val(3), p.beta*val(2); …
p.alpha, -p.beta*val(3)-2*p.gamma*val(2), -p.beta*val(2); …
0, 2*p.gamma*val(2), 0];
F = ki – f_val;
DF = eye(3) – h*A(i,i)*jac;
step = DFF;
ki = ki – step;
if max(abs(step)) < 1e-8, break; end
if iter == 5, conv = false; end
end
K(:,i) = ki;
end
ynext = y + h*(K*b’);
yhat = y + h*(K*bhat’);
endI would like to know if this code can be improved/optimized. is it well-written? Any help will be appreciated. Thanks
function main_solver_optimized()
params.alpha = 0.04; params.beta = 1e4; params.gamma = 3e7;
y0 = [1; 0; 0];
tspan = [0, 1e6];
h0 = 1e-4;
tol = 1e-2;
fprintf(‘Running Part 1: Radau IIA (2-stage vs 3-stage)…n’);
[T1, Y1, s1, r1] = solve_robertson(y0, tspan, h0, tol, params, ‘Radau’);
fprintf(‘Running Part 2: SDIRK 3(4)…n’);
[T2, Y2, s2, r2] = solve_robertson(y0, tspan, h0, tol, params, ‘SDIRK’);
fprintf(‘n================ RESULTS COMPARISON ================n’);
fprintf(‘Method | Successful Steps | Rejected Stepsn’);
fprintf(‘—————————————————-n’);
fprintf(‘Radau IIA | %16d | %14dn’, s1, r1);
fprintf(‘SDIRK 3(4) | %16d | %14dn’, s2, r2);
fprintf(‘====================================================n’);
figure(‘Name’, ‘Robertson Problem Solutions’);
subplot(2,1,1);
semilogx(T1, Y1(:,1), T1, Y1(:,2)*1e4, T1, Y1(:,3), ‘LineWidth’, 1.5);
title(‘Part 1: Radau IIA Method’); xlabel(‘Time (s)’); ylabel(‘Concentration’);
legend(‘y_1’, ‘y_2 times 10^4’, ‘y_3’, ‘Location’, ‘Best’); grid on;
subplot(2,1,2);
semilogx(T2, Y2(:,1), T2, Y2(:,2)*1e4, T2, Y2(:,3), ‘LineWidth’, 1.5);
title(‘Part 2: SDIRK 3(4) Method’); xlabel(‘Time (s)’); ylabel(‘Concentration’);
legend(‘y_1’, ‘y_2 times 10^4’, ‘y_3’, ‘Location’, ‘Best’); grid on;
end
function [T, Y, success, rejected] = solve_robertson(y0, tspan, h, tol, p, method)
Nmax = 1e6;
T = zeros(Nmax,1); Y = zeros(Nmax,3);
t = tspan(1); y = y0;
T(1) = t; Y(1,:) = y’;
stepCount = 1;
success = 0; rejected = 0;
if strcmp(method,’Radau’)
A2 = [5/12, -1/12; 3/4, 1/4]; c2 = [1/3, 1]’;
sq6 = sqrt(6);
A3 = [(88-7*sq6)/360, (296-169*sq6)/1800, (-2+3*sq6)/225; …
(296+169*sq6)/1800, (88+7*sq6)/360, (-2-3*sq6)/225; …
(16-sq6)/36, (16+sq6)/36, 1/9];
c3 = [(4-sq6)/10, (4+sq6)/10, 1]’;
solver_func = @(y,h) solve_radau_adaptive(y,h,A2,c2,A3,c3,p);
order_p = 3;
else
gam = 1/4;
A = [gam, 0, 0, 0, 0;
1/2-gam, gam, 0, 0, 0;
2*gam, 1-4*gam, gam, 0, 0;
1/10, 1/10, 1/10+gam, gam, 0;
1/4, 1/4, 0, 1/4, gam];
c = [1/4, 3/4, 11/20, 1/2, 1]’;
b = [1/4, 1/4, 0, 1/4, 1/4];
bhat = [-3/16, 5/8, 3/16, 1/16, 5/16];
solver_func = @(y,h) solve_sdirk_sequential(y,h,A,b,bhat,c,p);
order_p = 3;
end
while t < tspan(2)
if t + h > tspan(2), h = tspan(2) – t; end
[y_n, y_hat, converged] = solver_func(y,h);
if converged
err = max(abs(y_n – y_hat));
if err <= tol
t = t + h; y = y_n;
stepCount = stepCount + 1;
T(stepCount) = t;
Y(stepCount,:) = y’;
success = success + 1;
h = h * min(5, max(0.1, 0.9*(tol/err)^(1/(order_p+1))));
else
h = h/4; rejected = rejected + 1;
end
else
h = h/4; rejected = rejected + 1;
end
end
T = T(1:stepCount); Y = Y(1:stepCount,:);
end
function [ynext, yhat, conv] = solve_radau_adaptive(y, h, A2, c2, A3, c3, p)
ynext = y + 0;
yhat = y + 0;
conv = true;
end
function [ynext, yhat, conv] = solve_sdirk_sequential(y, h, A, b, bhat, c, p)
s = length(c);
K = zeros(3,s);
conv = true;
for i = 1:s
ki = zeros(3,1);
rhs = y + h*(K(:,1:i-1)*A(i,1:i-1)’);
for iter = 1:5
val = rhs + h*A(i,i)*ki;
f_val = [-p.alpha*val(1) + p.beta*val(2)*val(3); …
p.alpha*val(1) – p.beta*val(2)*val(3) – p.gamma*val(2)^2; …
p.gamma*val(2)^2];
jac = [-p.alpha, p.beta*val(3), p.beta*val(2); …
p.alpha, -p.beta*val(3)-2*p.gamma*val(2), -p.beta*val(2); …
0, 2*p.gamma*val(2), 0];
F = ki – f_val;
DF = eye(3) – h*A(i,i)*jac;
step = DFF;
ki = ki – step;
if max(abs(step)) < 1e-8, break; end
if iter == 5, conv = false; end
end
K(:,i) = ki;
end
ynext = y + h*(K*b’);
yhat = y + h*(K*bhat’);
end I would like to know if this code can be improved/optimized. is it well-written? Any help will be appreciated. Thanks
function main_solver_optimized()
params.alpha = 0.04; params.beta = 1e4; params.gamma = 3e7;
y0 = [1; 0; 0];
tspan = [0, 1e6];
h0 = 1e-4;
tol = 1e-2;
fprintf(‘Running Part 1: Radau IIA (2-stage vs 3-stage)…n’);
[T1, Y1, s1, r1] = solve_robertson(y0, tspan, h0, tol, params, ‘Radau’);
fprintf(‘Running Part 2: SDIRK 3(4)…n’);
[T2, Y2, s2, r2] = solve_robertson(y0, tspan, h0, tol, params, ‘SDIRK’);
fprintf(‘n================ RESULTS COMPARISON ================n’);
fprintf(‘Method | Successful Steps | Rejected Stepsn’);
fprintf(‘—————————————————-n’);
fprintf(‘Radau IIA | %16d | %14dn’, s1, r1);
fprintf(‘SDIRK 3(4) | %16d | %14dn’, s2, r2);
fprintf(‘====================================================n’);
figure(‘Name’, ‘Robertson Problem Solutions’);
subplot(2,1,1);
semilogx(T1, Y1(:,1), T1, Y1(:,2)*1e4, T1, Y1(:,3), ‘LineWidth’, 1.5);
title(‘Part 1: Radau IIA Method’); xlabel(‘Time (s)’); ylabel(‘Concentration’);
legend(‘y_1’, ‘y_2 times 10^4’, ‘y_3’, ‘Location’, ‘Best’); grid on;
subplot(2,1,2);
semilogx(T2, Y2(:,1), T2, Y2(:,2)*1e4, T2, Y2(:,3), ‘LineWidth’, 1.5);
title(‘Part 2: SDIRK 3(4) Method’); xlabel(‘Time (s)’); ylabel(‘Concentration’);
legend(‘y_1’, ‘y_2 times 10^4’, ‘y_3’, ‘Location’, ‘Best’); grid on;
end
function [T, Y, success, rejected] = solve_robertson(y0, tspan, h, tol, p, method)
Nmax = 1e6;
T = zeros(Nmax,1); Y = zeros(Nmax,3);
t = tspan(1); y = y0;
T(1) = t; Y(1,:) = y’;
stepCount = 1;
success = 0; rejected = 0;
if strcmp(method,’Radau’)
A2 = [5/12, -1/12; 3/4, 1/4]; c2 = [1/3, 1]’;
sq6 = sqrt(6);
A3 = [(88-7*sq6)/360, (296-169*sq6)/1800, (-2+3*sq6)/225; …
(296+169*sq6)/1800, (88+7*sq6)/360, (-2-3*sq6)/225; …
(16-sq6)/36, (16+sq6)/36, 1/9];
c3 = [(4-sq6)/10, (4+sq6)/10, 1]’;
solver_func = @(y,h) solve_radau_adaptive(y,h,A2,c2,A3,c3,p);
order_p = 3;
else
gam = 1/4;
A = [gam, 0, 0, 0, 0;
1/2-gam, gam, 0, 0, 0;
2*gam, 1-4*gam, gam, 0, 0;
1/10, 1/10, 1/10+gam, gam, 0;
1/4, 1/4, 0, 1/4, gam];
c = [1/4, 3/4, 11/20, 1/2, 1]’;
b = [1/4, 1/4, 0, 1/4, 1/4];
bhat = [-3/16, 5/8, 3/16, 1/16, 5/16];
solver_func = @(y,h) solve_sdirk_sequential(y,h,A,b,bhat,c,p);
order_p = 3;
end
while t < tspan(2)
if t + h > tspan(2), h = tspan(2) – t; end
[y_n, y_hat, converged] = solver_func(y,h);
if converged
err = max(abs(y_n – y_hat));
if err <= tol
t = t + h; y = y_n;
stepCount = stepCount + 1;
T(stepCount) = t;
Y(stepCount,:) = y’;
success = success + 1;
h = h * min(5, max(0.1, 0.9*(tol/err)^(1/(order_p+1))));
else
h = h/4; rejected = rejected + 1;
end
else
h = h/4; rejected = rejected + 1;
end
end
T = T(1:stepCount); Y = Y(1:stepCount,:);
end
function [ynext, yhat, conv] = solve_radau_adaptive(y, h, A2, c2, A3, c3, p)
ynext = y + 0;
yhat = y + 0;
conv = true;
end
function [ynext, yhat, conv] = solve_sdirk_sequential(y, h, A, b, bhat, c, p)
s = length(c);
K = zeros(3,s);
conv = true;
for i = 1:s
ki = zeros(3,1);
rhs = y + h*(K(:,1:i-1)*A(i,1:i-1)’);
for iter = 1:5
val = rhs + h*A(i,i)*ki;
f_val = [-p.alpha*val(1) + p.beta*val(2)*val(3); …
p.alpha*val(1) – p.beta*val(2)*val(3) – p.gamma*val(2)^2; …
p.gamma*val(2)^2];
jac = [-p.alpha, p.beta*val(3), p.beta*val(2); …
p.alpha, -p.beta*val(3)-2*p.gamma*val(2), -p.beta*val(2); …
0, 2*p.gamma*val(2), 0];
F = ki – f_val;
DF = eye(3) – h*A(i,i)*jac;
step = DFF;
ki = ki – step;
if max(abs(step)) < 1e-8, break; end
if iter == 5, conv = false; end
end
K(:,i) = ki;
end
ynext = y + h*(K*b’);
yhat = y + h*(K*bhat’);
end code improvement MATLAB Answers — New Questions









