From: Jan Simon on
Dear Christopher,

> yes x is a scalar.. but it is a variable in which i need to be evaluated to minimize the function. . how can I create a vector with seventeen variables? Is that possible?

Matlab is a powerful language. It is almost imposible to use it without learning. So I strongly recommend to read the "Getting started" section of the documentation.

Kind regards, Jan
From: Steven_Lord on


"Christopher " <christopher.serojano(a)veco.com.ph> wrote in message
news:i3tii1$nbd$1(a)fred.mathworks.com...
> "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message
> <i3tiah$bh2$1(a)fred.mathworks.com>...
>> "Christopher " <christopher.serojano(a)veco.com.ph> wrote in message
>> <i3thee$btv$1(a)fred.mathworks.com>...
>> > Hi,
>> >
>> > I am trying to use a lot of variables for my function but the
>> > optimization toolbox states that variable out of bounds because
>> > numel(x) = 2 and I can only use two variables say x(1) and x(2). . how
>> > can I increase the number of variables say using x(3),x(4),x(5),x(6)...
>> > etc.. . Can Anyone help me. . pls
>>
>> MATLAB can hold roughly 65000 variables, so I doubt you are running into
>> that limit. We can't possibly help you unless you provide more details,
>> and ideally some code for us to look at.
>>
>> James Tursa
>
> thank you for your reply this is my code. .
> function f = objfun(x)
> a = xlsread('Optimization','weekday','c8:h103'); %demand CEDC - NPC
> b = xlsread('Optimization','weekday','l8:m31'); % NPC rates
> c = xlsread('Optimization','weekday','q7:q12'); % other rates
> d = xlsread('Optimization','weekday','q13:q14');% Cemex and CPPC capacity
> fee

You're reading in four Excel spreadsheets EACH TIME THE SOLVER RUNS THIS
FUNCTION. That's going to absolutely murder the performance of your code.
If the spreadsheets do not change during the running of this code (as I hope
is the case), read in the data ONCE _outside_ this function and pass the
variables containing the data into this function as additional input
arguments.

> e = a(:,2).*0.25.*c(4,1); %Cost for CEDC per 15 min
> i = 0.25.*c(5,1); %Cost for TPC per 15 min
> g = 0.25.*c(1,1); % Cost for CPPC per 15 min
> %Cost of NPC for every one hour
> h = [sum(a(1:4,5)).*b(1,1).*0.25 sum(a(5:8,5)).*b(2,1).*0.25
> sum(a(9:12,5)).*b(3,1).*0.25 sum(a(13:16,5)).*b(4,1).*0.25
> sum(a(17:20,5)).*b(5,1).*0.25 sum(a(21:24,5)).*b(6,1).*0.25...
> sum(a(25:28,5)).*b(7,1).*0.25 sum(a(29:32,5)).*b(8,1).*0.25
> sum(a(33:36,5)).*b(9,1).*0.25 sum(a(37:40,5)).*b(10,1).*0.25
> sum(a(41:44,5)).*b(11,1).*0.25 sum(a(45:48,5)).*b(12,1).*0.25...
> sum(a(49:52,5)).*b(13,1).*0.25 sum(a(53:56,5)).*b(14,1).*0.25
> sum(a(57:60,5)).*b(15,1).*0.25 sum(a(61:64,5)).*b(16,1).*0.25
> sum(a(65:68,5)).*b(17,1).*0.25 sum(a(69:72,5)).*b(18,1).*0.25...
> sum(a(73:76,5)).*b(19,1).*0.25 sum(a(77:80,5)).*b(20,1).*0.25
> sum(a(81:84,5)).*b(21,1).*0.25 sum(a(85:88,5)).*b(22,1).*0.25
> sum(a(89:92,5)).*b(23,1).*0.25 sum(a(93:96,5)).*b(24,1).*0.25]';
>
> f = sum(e) + x(1)*c(5,1)*0.25 + x(2)*c(5,1)*0.25
> +x(3)*c(5,1)*0.25+x(4)*c(5,1)*0.25+x(5)*c(5,1)*0.25+x(6)*c(5,1)*0.25+x(7)*c(5,1)*0.25+x(8)*c(5,1)*0.25+x(9)*c(5,1)*0.25+x(10)*c(5,1)*0.25+x(11)*c(5,1)*0.25+x(12)*c(5,1)*0.25+x(13)*c(5,1)*0.25+x(14)*c(5,1)*0.25+x(15)*c(5,1)*0.25+x(16)*c(5,1)*0.25+...
> x(17)*c(5,1)*0.25

So this requires the x with which the solver calls this function to contain
17 elements. That in turn requires the initial guess (x0) that you pass
into that solver to contain 17 elements. Show us how you call the solver
with this function as input.

Once you have the code working and receiving a 17-element x, then you can do
the additional input argument work I described above using this page as a
guide:

http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-7.html

But don't try this until you've solved the problem with x being the wrong
size.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

From: Walter Roberson on
Jan Simon wrote:

> Matlab is a powerful language. It is almost imposible to use it without
> learning.

I have a Chinese Room that disputes that ;-)
First  |  Prev  | 
Pages: 1 2 3
Prev: MATLAB IFFT
Next: subplots with different color maps