Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

matlab - How to Compute f(x) for a=1 and various values of the parameter b on the interval 0<x<3

I tried using below codes with no luck

f = 0;
a = 1;
b = [1 2 3.5];

for x = 0:3
  f = (a * b * x).^(b-1)*exp(-a*x.^b);
end 

disp (f);
question from:https://stackoverflow.com/questions/65876875/how-to-compute-fx-for-a-1-and-various-values-of-the-parameter-b-on-the-interva

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming the domain is x and the comparison parameter is b we can loop through the values of b to create three distinct vectors for which the function, f is plotted for. Here the value of b is swapped on each iteration of the for-loop. The resultant end up being f with 3 rows by 4 columns where the columns correspond to the x-values/domain and the rows correspond to the value of parameter, b.

Output Plot/Results

x = (0:3);
a = 1;
B = [1 2 3.5];

for Parameter_Index = 1: length(B)
    b = B(Parameter_Index);
    f(Parameter_Index,:) = (a.*b.*x).^(b-1).*exp(-a.*x.^b);
end

plot(x,f(1,:),x,f(2,:),x,f(3,:));
xlabel("x"); ylabel("f(x)");
legend("B = " + num2str(B(1)),"B = " + num2str(B(2)),"B = " + num2str(B(3)));

Ran using MATLAB R2019b


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...