I DONT KNOW HOW TO CODE AND PLOT THIS EQUATION

1 vue (au cours des 30 derniers jours)
korukosheep
korukosheep le 6 Déc 2020
Commenté : Image Analyst le 7 Déc 2020
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

Réponses (1)

Image Analyst
Image Analyst le 6 Déc 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 commentaires
Walter Roberson
Walter Roberson le 7 Déc 2020
post your current code
Image Analyst
Image Analyst le 7 Déc 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by