
I DONT KNOW HOW TO CODE AND PLOT THIS EQUATION
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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 个评论
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 Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!