plotting functions from book

조회 수: 11 (최근 30일)
Faisal Al-Wazir
Faisal Al-Wazir 2022년 10월 1일
댓글: Faisal Al-Wazir 2022년 10월 2일
hi i'm trying to plot this function and get the same result from the book
the function:
the plot in the book;
this is my code
i need to find a way to make the plot smother
c=1
c = 1
for k=1.2:0.4:2.8
u=linspace(0,2.8,5)
u1=0:0.01:2,4
f=(k/c).*(u/c).^(k-1).*exp(-(u/c).^(k))
plot(u,f)
hold on
end
u = 1×5
0 0.7000 1.4000 2.1000 2.8000
u1 = 1×201
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300 0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000 0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700 0.2800 0.2900
ans = 4
f = 1×5
0 0.5823 0.2871 0.1218 0.0473
u = 1×5
0 0.7000 1.4000 2.1000 2.8000
u1 = 1×201
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300 0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000 0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700 0.2800 0.2900
ans = 4
f = 1×5
0 0.7341 0.3530 0.0942 0.0165
u = 1×5
0 0.7000 1.4000 2.1000 2.8000
u1 = 1×201
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300 0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000 0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700 0.2800 0.2900
ans = 4
f = 1×5
0 0.8577 0.3944 0.0511 0.0022
u = 1×5
0 0.7000 1.4000 2.1000 2.8000
u1 = 1×201
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300 0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000 0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700 0.2800 0.2900
ans = 4
f = 1×5
0 0.9524 0.4083 0.0180 0.0001
u = 1×5
0 0.7000 1.4000 2.1000 2.8000
u1 = 1×201
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300 0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000 0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700 0.2800 0.2900
ans = 4
f = 1×5
0 1.0194 0.3945 0.0036 0.0000

채택된 답변

Torsten
Torsten 2022년 10월 1일
편집: Torsten 2022년 10월 1일
c = 1;
k = 1.2:0.4:2.8;
u = (linspace(0,2.4,100)).';
f = (k/c).*(u/c).^(k-1).*exp(-(u/c).^(k));
plot(u,f)
  댓글 수: 2
Ethan McDonald
Ethan McDonald 2022년 10월 1일
I believe Torsten's solutions solves your issue, but I wanted to comment to let you know you should avoid using for-loops when possible. Matlab is much quicker at processing vectos and matrices, and in many case, you can take advantage of GPU computing for large amounts of data.
Faisal Al-Wazir
Faisal Al-Wazir 2022년 10월 2일
thanks i'll keep that in mind

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by