
I DONT KNOW HOW TO CODE AND PLOT THIS EQUATION
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Image Analyst
on 6 Dec 2020
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 Comments
Image Analyst
on 7 Dec 2020
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.
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!