How to plot a log log equation

조회 수: 7 (최근 30일)
Okechukwu Anene
Okechukwu Anene 2018년 3월 7일
댓글: Akira Agata 2018년 3월 8일
I am trying to plot the following equation in matlab.. log ts = log c + nlog(v/a). I am required to find the value of c(which is the intercept) and n(which is the slope). The plot is ts against v/a.
Pls how do i proceed on this?
  댓글 수: 2
Benjamin Kraus
Benjamin Kraus 2018년 3월 7일
Can you please clarify...
You said you want to plot an equation, which you can only do if you know the values of c and n. However, you then say you are required to find the values of c and n, which suggests you have data you want to plot, then fit a curve to the data.
Are you trying to plot an equation, or are you trying to fit a line to your data to extract values for c and n?
Okechukwu Anene
Okechukwu Anene 2018년 3월 7일
I apologize for the confusion. Yes I have data that i want to plot. i have 4 values for Ts : 3.48, 15.78, 10.17 and 8.13. Also, values for v/a are: 0.226, 0.536, 0.416, 0.367.
I am required to plot Ts against v/a on a log log graph and to find the slope n and intercept c using matlab.
The equation of the line is log ts = log c + nlog (v/a).

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

답변 (1개)

Akira Agata
Akira Agata 2018년 3월 8일
It seems that your data can be better fitted by 'Ts = b1 + b2*(v/a)' rather than 'Ts = b1 + b2*log(v/a)'. Here is an example to fit the data and plot in log-log graph.
Ts = [3.48, 15.78, 10.17, 8.13]';
va = [0.226, 0.536, 0.416, 0.367]';
X1 = [ones(size(va)) va];
b1 = X1\Ts;
X2 = [ones(size(va)) log(va)];
b2 = X2\Ts;
vaa = linspace(0.2,0.6)';
Ts1 = [ones(size(vaa)), vaa]*b1;
Ts2 = [ones(size(vaa)), log(vaa)]*b2;
loglog(va,Ts,'o-')
hold on
loglog(vaa,Ts1)
loglog(vaa,Ts2)
legend({'Data','Ts = b1 + b2*va','Ts = b1 + b2*log(va)'})
xlabel('v/a','FontSize',12)
ylabel('Ts','FontSize',12)
grid on
  댓글 수: 2
Okechukwu Anene
Okechukwu Anene 2018년 3월 8일
Thank you so much for your response. however am running into some issues applying the code. I attached a screenshot of the error. Pls what do you think?
Thanks so much
Akira Agata
Akira Agata 2018년 3월 8일
Hi Okechukwu-san,
Please insert space between 'ones(size(va))' and 'va', or just copy&paste my sample code.

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

카테고리

Help CenterFile Exchange에서 Data Logging에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by