I DONT KNOW HOW TO CODE AND PLOT THIS EQUATION

1 回表示 (過去 30 日間)
korukosheep
korukosheep 2020 年 12 月 6 日
コメント済み: Image Analyst 2020 年 12 月 7 日
i been trying to code and plot this Midilli equation but it's very hard for me and i dont know how to start it
MR= a•exp(-k(t^n))+b•t
where any numbers can be put in a,b,k,n,t

回答 (1 件)

Image Analyst
Image Analyst 2020 年 12 月 6 日
Did you try the plot() function?
% Ask user for four floating point numbers.
defaultValue = {'4', '2', '3', '3'};
titleBar = 'Enter a value';
userPrompt = {'Enter a : ', 'Enter b : ', 'Enter k : ', 'Enter n : '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Convert to floating point from string.
a = str2double(caUserInput{1})
b = str2double(caUserInput{2})
k = str2double(caUserInput{3})
n = str2double(caUserInput{4})
t = linspace(0, 3, 1000);
MR = a*exp(-k*(t.^n))+b*t;
% where any numbers can be put in a,b,k,n,t
plot(t, MR, 'b-', 'LineWidth', 2);
grid on;
xlabel('t', 'FontSize', 20);
ylabel('MR', 'FontSize', 20);
title('MR vs. t', 'FontSize', 20);
  5 件のコメント
Walter Roberson
Walter Roberson 2020 年 12 月 7 日
post your current code
Image Analyst
Image Analyst 2020 年 12 月 7 日
Maybe it's some sort of regional keyboard setting problem. Try changing it. If the decimal point shows up in some other character, maybe you can try input() instead of inputdlg() to enter numbers directly. Otherwise, I've created a version with decimal points in there using the defaults you gave, and also gives you the value for t = 11 exactly.
% Ask user for four floating point numbers.
defaultValue = {'1.1143', '0.00321', '0.1791', '1.3215'}; % a = 1.1143 K = 0.1791 n = 1.3215 b = 0.00321 t = 11
titleBar = 'Enter a value';
userPrompt = {'Enter a : ', 'Enter b : ', 'Enter k : ', 'Enter n : '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Convert to floating point from string.
a = str2double(caUserInput{1})
b = str2double(caUserInput{2})
k = str2double(caUserInput{3})
n = str2double(caUserInput{4})
t = linspace(8, 12, 1000);
MR = a*exp(-k*(t.^n))+b*t;
% where any numbers can be put in a,b,k,n,t
plot(t, MR, 'b-', 'LineWidth', 2);
grid on;
xlabel('t', 'FontSize', 20);
ylabel('MR', 'FontSize', 20);
title('MR vs. t', 'FontSize', 20);
% Let's see where it is for t = 11
t11 = 11;
MR11 = a*exp(-k*(t11.^n))+b*t11
xline(t11, 'LineWidth', 2, 'Color', 'r');
yline(MR11, 'LineWidth', 2, 'Color', 'r');
caption = sprintf('MR vs. t. MR(%.1f) = %f', t11, MR11);
title(caption, 'FontSize', 20);
If it still doesn't work, post your code.

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by