I want to create a matlab program to perform this operation and show the result in each operation in table

2 views (last 30 days)
X(i)=sumation of x(i-k)*f(k) Where i=1:200,k=1:i,f(k) is a function
  21 Comments
Maha Ahmed
Maha Ahmed on 10 Jul 2021
function varargout = demand(varargin)
% DEMAND MATLAB code for demand.fig
% DEMAND, by itself, creates a new DEMAND or raises the existing
% singleton*.
%
% H = DEMAND returns the handle to a new DEMAND or the handle to
% the existing singleton*.
%
% DEMAND('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DEMAND.M with the given input arguments.
%
% DEMAND('Property','Value',...) creates a new DEMAND or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before demand_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to demand_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help demand
% Last Modified by GUIDE v2.5 05-Jul-2021 16:07:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @demand_OpeningFcn, ...
'gui_OutputFcn', @demand_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before demand is made visible.
function demand_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to demand (see VARARGIN)
% Choose default command line output for demand
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes demand wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = demand_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function Ar_edit_Callback(hObject, eventdata, handles)
% hObject handle to Ar_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Ar_edit as text
% str2double(get(hObject,'String')) returns contents of Ar_edit as a double
% --- Executes during object creation, after setting all properties.
function Ar_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Ar_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function sigmar_edit_Callback(hObject, eventdata, handles)
% hObject handle to sigmar_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of sigmar_edit as text
% str2double(get(hObject,'String')) returns contents of sigmar_edit as a double
% --- Executes during object creation, after setting all properties.
function sigmar_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to sigmar_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Mr_edit_Callback(hObject, eventdata, handles)
% hObject handle to Mr_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Mr_edit as text
% str2double(get(hObject,'String')) returns contents of Mr_edit as a double
% --- Executes during object creation, after setting all properties.
function Mr_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Mr_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function alfa_edit_Callback(hObject, eventdata, handles)
% hObject handle to alfa_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of alfa_edit as text
% str2double(get(hObject,'String')) returns contents of alfa_edit as a double
% --- Executes during object creation, after setting all properties.
function alfa_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to alfa_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function bf_edit_Callback(hObject, eventdata, handles)
% hObject handle to bf_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of bf_edit as text
% str2double(get(hObject,'String')) returns contents of bf_edit as a double
% --- Executes during object creation, after setting all properties.
function bf_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to bf_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function kf_edit_Callback(hObject, eventdata, handles)
% hObject handle to kf_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of kf_edit as text
% str2double(get(hObject,'String')) returns contents of kf_edit as a double
% --- Executes during object creation, after setting all properties.
function kf_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to kf_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Af_edit_Callback(hObject, eventdata, handles)
% hObject handle to Af_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Af_edit as text
% str2double(get(hObject,'String')) returns contents of Af_edit as a double
% --- Executes during object creation, after setting all properties.
function Af_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Af_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function sigmaf_edit_Callback(hObject, eventdata, handles)
% hObject handle to sigmaf_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of sigmaf_edit as text
% str2double(get(hObject,'String')) returns contents of sigmaf_edit as a double
% --- Executes during object creation, after setting all properties.
function sigmaf_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to sigmaf_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Mf_edit_Callback(hObject, eventdata, handles)
% hObject handle to Mf_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Mf_edit as text
% str2double(get(hObject,'String')) returns contents of Mf_edit as a double
% --- Executes during object creation, after setting all properties.
function Mf_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Mf_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in demand_push.
function demand_push_Callback(hObject, eventdata, handles)
% hObject handle to demand_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Alfa = str2double(get(handles.alfa_edit,'string'));
bf = str2double(get(handles.bf_edit,'string'));
kf = str2double(get(handles.kf_edit,'string'));
Af = str2double(get(handles.Af_edit,'string'));
sigmaf = str2double(get(handles.sigmaf_edit,'string' ));
Mf = str2double(get(handles.Mf_edit,'string'));
t=1:200;
f=@(t)(Alfa/bf)*kf*(t.^(kf-1)).*exp(-((t.^kf)/bf))+(1-Alfa)*(1/(Af*sigma-f*((2*pi)^0.5))).*exp(-(((t-Mf).^2)/(2*(sigmaf.^2))));
Ar = str2double(get(handles.Ar_edit,'string'));
sigmar = str2double(get(handles.sigmar_edit,'string'));
Mr = str2double(get(handles.Mr_edit,'string'));
t=1:200;
R=@(t)1-(1/(Ar*sigma-r*((2*pi)^0.5))).*exp(-(((t-Mr).^2)/(2*(sigmar.^2))));
for t=2:200
sum=0
for j=2:t
sum=sum+sum(t-j).*f(j)
end
v(t)=sum
end
val=get(handles.popupmenu1,'value');
str=get(handles.popupmenu1,'num');
switch str{val};
case 10000;
p=10000;
case 20000;
p=20000;
case 30000;
p=30000;
case 50000;
p=50000;
end
d(1)=0
for t=2:200
total=0
for l=1:t-1
total=total+v(t-l).*R(t-l).*p
end
d(t)=total
end
Demand =d(t)
m=dub2str(set(handles.demand_edit,'string',Demand))
function demand_edit_Callback(hObject, eventdata, handles)
% hObject handle to demand_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of demand_edit as text
% str2double(get(hObject,'String')) returns contents of demand_edit as a double
% --- Executes during object creation, after setting all properties.
function demand_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to demand_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
when i run this gui program, i get this error massage
what should i do
sum =
0
Array indices must be positive integers or logical values.
Error in demand>demand_push_Callback (line 332)
sum=sum+sum(t-j).*f(j)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in demand (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)demand('demand_push_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Walter Roberson
Walter Roberson on 11 Jul 2021
for t=2:200
sum=0
for j=2:t
sum=sum+sum(t-j).*f(j)
end
v(t)=sum
end
t starts at 2. j starts at 2. t-j starts at 0. sum starts at the scalar 0. sum(t-j) would be sum(0) which is an invalid index.
The associated logic never stores more than 1 value in sum so sum can only be indexed at 1 (or true)
Reminder that matlab does not support implied multiplication. If you want multiplication then you need to use a multiplication operator.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Jun 2021
x = @(K) pi*exp(-(K-3).^2);
a = rand();
b = rand();
bounds = sort(rand(1,2))
bounds = 1×2
0.2767 0.5438
pd = makedist('Weibull','a',a,'b',b);
pdd = truncate(pd, bounds(1), bounds(2))
pdd =
WeibullDistribution Weibull distribution A = 0.500496 B = 0.36551 Truncated to the interval [0.276723, 0.543765]
f = @(k) cdf(pdd, k)
f = function_handle with value:
@(k)cdf(pdd,k)
for i = 1 : 200
itotal = 0;
for k = 1 : i
itotal = itotal + x(i-k)*f(k);
end
X(i) = itotal;
end
X
X = 1×200
0.0004 0.0579 1.2137 4.3552 5.5110 5.5685 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689 5.5689
  7 Comments
Walter Roberson
Walter Roberson on 1 Jul 2021
f=@(t) (al/b)*k*(t.^(k-1)).*exp(-((t.^k)/b))+(1-al)*(1/(at*sig*(2*pi)^.5))).*exp(-(t-mu).^2/(2*(sig.^2)))
1 0 1 0 1 2 10 1 23 2 10 1 0 1 2 3 2 10! 0 1 0 1 2 10!
Here ! means the open-bracket count has gone to negative 1.

Sign in to comment.

More Answers (2)

Mahaveer Singh
Mahaveer Singh on 13 Jul 2021
S=0;
x(1)=0; % initial value of x.
for i=2:1:200
for k=1:1:i-1
S(k)=x(i-k).*f(k);
end
x(i)=sum(S);
end
sumation=x

Sara Boznik
Sara Boznik on 27 Jun 2021
part=0;
sumation=0;
for i=1:1:200
for k=1:1:i
part=x(i-k).*f(k)
sumation=sumation+part
end
end
Sumation is x(i).
  4 Comments
Maha Ahmed
Maha Ahmed on 27 Jun 2021
f(k) is weibull trankated normal distribution function ,all parameters are known, k is the only variable Alfa(i)=sumation of (alfa(i-k)*f(k)), these sumation from k=1tok=i, and i=1to 200

Sign in to comment.

Categories

Find more on Data Type Identification in Help Center and File Exchange

Tags

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!