
I DONT KNOW HOW TO CODE AND PLOT THIS EQUATION
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Image Analyst
am 6 Dez. 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 Kommentare
Image Analyst
am 7 Dez. 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.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!