フィルターのクリア

how can i convert from one value to multi values

1 回表示 (過去 30 日間)
work wolf
work wolf 2022 年 6 月 19 日
コメント済み: work wolf 2022 年 6 月 23 日
how can i replace value of
alpha = 0.5
by multi values as
alpha =[0.1 0.3 0.5 0.6 0.66 0.9 1]
in the following code:
alpha = 0.5;
u0 = 0;
a_k = @(k) (k + 1)^(1 - alpha) - (k)^(1 - alpha);
n = 100;
a = 0;
b = 1;
h = (b - a) / n;
t = a:h:b;
f = @(t,u) (-u.^4) + (gamma(2*alpha+1) ./ gamma(alpha+1) ) .* (t.^alpha) - ...
(2./gamma(3 - alpha) ) .* (t.^(2 - alpha)) + (t.^(2*alpha) - t.^2).^4;
up = zeros(1, n);
uc = zeros(1, n);
zp = zeros(1, n);
uc = zeros(1, n); % ??? is this your "u"?
C = gamma(2 - alpha) * h ^ alpha;
for ni = 1:n
up(ni) = a_k(ni - 1) * u0;
for k = 1:ni - 1
up(ni) = up(ni) + (a_k(ni - 1 - k) - a_k(ni - k)) * uc(k);
end
zp(ni) = C * f(t(ni), up(ni));
uc(ni) = up(ni) + C * f(t(ni), up(ni) + zp(ni));
end
fprintf('%g\n', up(1:20))
  2 件のコメント
Muhammad Usman Saleem
Muhammad Usman Saleem 2022 年 6 月 19 日
try to use intp1 functio in matlab
work wolf
work wolf 2022 年 6 月 20 日

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2022 年 6 月 20 日
Try this:
% Define all the alphas that we want to use.
allAlpha =[0.1 0.3 0.5 0.6 0.66 0.9 1]
% Iterate the code for each value of alpha.
for kk = 1 : length(allAlpha)
alpha = allAlpha(kk);
% Existing code below:
u0 = 0;
a_k = @(k) (k + 1)^(1 - alpha) - (k)^(1 - alpha);
n = 100;
a = 0;
b = 1;
h = (b - a) / n;
t = a:h:b;
f = @(t,u) (-u.^4) + (gamma(2*alpha+1) ./ gamma(alpha+1) ) .* (t.^alpha) - ...
(2./gamma(3 - alpha) ) .* (t.^(2 - alpha)) + (t.^(2*alpha) - t.^2).^4;
up = zeros(1, n);
uc = zeros(1, n);
zp = zeros(1, n);
uc = zeros(1, n); % ??? is this your "u"?
C = gamma(2 - alpha) * h ^ alpha;
for ni = 1:n
up(ni) = a_k(ni - 1) * u0;
for k = 1:ni - 1
up(ni) = up(ni) + (a_k(ni - 1 - k) - a_k(ni - k)) * uc(k);
end % of k loop
zp(ni) = C * f(t(ni), up(ni));
uc(ni) = up(ni) + C * f(t(ni), up(ni) + zp(ni));
end % of ni loop
fprintf('%g\n', up(1:20))
end % of kk loop
  6 件のコメント
work wolf
work wolf 2022 年 6 月 21 日
i did it, but give me all output, zores !!
% Define all the alphas that we want to use.
allAlpha =[0.1 0.3 0.5 0.6 0.66 0.9 1];
% Iterate the code for each value of alpha.
for kk = 1 : length(allAlpha)
alpha = allAlpha(kk);
% Existing code below:
u0 = 0;
a_k = @(k) (k + 1)^(1 - alpha) - (k)^(1 - alpha);
n = 100;
a = 0;
b = 1;
h = (b - a) / n;
t = a:h:b;
f = @(t,u) (-u.^4) + (gamma(2*alpha+1) ./ gamma(alpha+1) ) .* (t.^alpha) - ...
(2./gamma(3 - alpha) ) .* (t.^(2 - alpha)) + (t.^(2*alpha) - t.^2).^4;
up = zeros(kk, n+1);
uc = zeros(kk, n+1);
zp = zeros(kk, n+1);
% uc = zeros(kk, n+1); % ??? is this your "u"?
C = gamma(2 - alpha) * h ^ alpha;
for ni = 1:n+1 %length(t)
% up(ni) = a_k(ni - 1) * u0;
up(kk,ni) = a_k(ni - 1) * u0; %modfied
for k = 1:ni - 1
% up(ni) = up(ni) + (a_k(ni - 1 - k) - a_k(ni - k)) * uc(k);
up(kk,ni) = up(kk,ni) + (a_k(ni - 1 - k) - a_k(ni - k)) * uc(kk,k); % modfied
end % of k loop
% zp(ni) = C * f(t(ni), up(ni));
% uc(ni) = up(ni) + C * f(t(ni), up(ni) + zp(ni));
zp(kk, ni) = C * f(t(ni), up(kk,ni)); % modfied
uc(kk, ni) = up(kk,ni) + C * f(t(ni), up(kk,ni) + zp(kk,ni)); % modfied
end % of ni loop
% fprintf('%g\n', up(1:20))
end % of kk loop
up
gives,
up =
Columns 1 through 13
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 14 through 26
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 27 through 39
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 40 through 52
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 53 through 65
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 66 through 78
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 79 through 91
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 92 through 101
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
work wolf
work wolf 2022 年 6 月 23 日
@Image Analyst thank you so much again. it's done with edite
up = zeros(kk, n+1);
uc = zeros(kk, n+1);
zp = zeros(kk, n+1);
before loop (for kk = 1 : length(allAlpha) ) and replace kk by length(allAlpha).
Best regards

サインインしてコメントする。

その他の回答 (1 件)

Ayush Kumar Jaiswal
Ayush Kumar Jaiswal 2022 年 6 月 19 日
編集済み: Ayush Kumar Jaiswal 2022 年 6 月 19 日
You want to calculate that function at different values of alpha, it can done using
arrayfun (func, arr);

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by