HOW TO CODE AND PLOT EQUATION

I tried to code and plot this Midilli equation but it keep on saying “subscript indices must either be real positive integers or logicals”. I need to plot those decimals but i dont know how
a= 1.1143 k= 0.1791 n= 0.3215 b= 0.00321 t = 11 mins
MR = a•exp(-k(t^n))+b•t

1 件のコメント

Ive J
Ive J 2020 年 12 月 7 日
MR = a*exp( -k*(t^n) ) + b*t; % consider .* in such cases

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 12 月 7 日

0 投票

You are missing multiplication operator between 'k' and t^n.
MR = a*exp(-k*(t^n))+b*t

5 件のコメント

korukosheep
korukosheep 2020 年 12 月 7 日
I see... but theres another problem,,, when i tried to put this a = 0.1143 it says “subscript indices must either be real positive integers or logicals”
Walter Roberson
Walter Roberson 2020 年 12 月 7 日
post your current code
korukosheep
korukosheep 2020 年 12 月 7 日
編集済み: Walter Roberson 2020 年 12 月 7 日
This is the code i used with the help of Image Analyst
% 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);
But when i tried to change the values of a,b,k,n to decimals it shows “subscript indices must either be real positive integers or logicals”
korukosheep
korukosheep 2020 年 12 月 7 日
I tried to input these values for
a= 1.1143 k= 0.1791 n= 1.3215 b= 0.00321
Walter Roberson
Walter Roberson 2020 年 12 月 7 日
at the command line give the command
clearvars
and then run the code again

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

カテゴリ

ヘルプ センター および File ExchangeGraph and Network Algorithms についてさらに検索

質問済み:

2020 年 12 月 7 日

コメント済み:

2020 年 12 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by