Hello everyone, I am stucked on how to write particular code for a Nash-Cournout oligopolistic equilibrium problem. I have written everything correctly and it ran successfully. The only situation I am in presently is trying to vary a particular step. To be more precise
I need code for the following:
is random for every
is random for every and
is random for every . I need to execute the following Quad program $c_j(x_j) = \frac{1}{2}x{_j}^{'} P_j x_j+ {q_j}^{'} x{_j}$. I will be glad if I can get a prompt help on this.
Thanks

 采纳的回答

Himanshu Rai
Himanshu Rai 2019-6-25
编辑:Himanshu Rai 2019-6-25
The expression below should solve your problem. Also write questions properly - would be scalar, so c is a vector. P and x are normal matrices, and q is a vector. This should solve your problem.
PS - Also update your question, and attach the image file there
c = x' * P * x / 2 + q' * x

8 个评论

Note $x_j$ is not a scalar, $x_j$ is a vector generated randomly in the interval (0,1] for each $j=1 \cdots 10.$
Himanshu Rai
Himanshu Rai 2019-6-25
编辑:Himanshu Rai 2019-6-25
From what is specified in the question appears to be a scalar value. The same goes for and
Sorry I need to include that, $x_j$ is a vector generated randomly in (0,1] for each j, $P_j$ is a matrix generated randomly in [1,40] and $q_j$ is also a vector generated randomly in [1,40]. Suppose $j$ runs from 1 to 10 and the dimension of the vector and matrix is m=3
From your comment , and , are the dimensions of your matrices. But this doesn't satisfy usual matix operation rules for the evaluation of you expression. Please specify more clearly, what (dimension of the) vector you are referring to, and by size of matrix to be 3 do you mean it is a square matrix ?
Thanks for your response. The matrix $P_j$ is a 3x3 matrix generated randomly in the interval [1,40]. $q_j$ is a 3x1$ generated randomly in [1,40] , $x_j$ is a 3x1 by matrix generated randomly in (0,1]. The indexed $j = 1 \cdots 10.$ This implies we have to generate $P_1$ $P_2$ up to $P_10.$ Same for $q_j$ and $x_j$.
Himanshu Rai
Himanshu Rai 2019-6-25
编辑:Himanshu Rai 2019-6-25
All right, so now I got what your question is, but still your dimensions doesn't satisfy rules of matrix opeations.
is , is , so will be .
is , is , so will be .
But we can't add these two results.
We need q_j to be 1by 3 as well
Well if is , then can't be calculated, because again the matrices are incompatible

请先登录,再进行评论。

更多回答(1 个)

Olawale Kazeem
Olawale Kazeem 2019-6-25

0 个投票

I just checked the mistake, hopefully I have not disturbed you too much. I am attaching a file that contains what I need.

10 个评论

I have updated my answer based on the image file you provided. Update your question, attach this file in the question and also don't comment as answer
Thanks, but I still don't understand how to treat the js, should I write each differently? I mean getting $c_1(x_1)$, $c_2(x_2)$, . separately. I need a code that can run everything together once.
How do I get a function going by what you suggested up there?
Use
sum(c) % here c is what you get from the expression in the answer
I get that, I hope this is my final question. What if my N is greater than the dimension of the matrices? It is clear now that the s are the entries of the vector x. If the vector is of dimension 10, but I need to sum up to $N=20$, how possible is this?
This doesn't make any sense - how can we add 20 elements, if there are only 10 elements in vector.
What I found out is that $c = sum(c) .$ Can you check that for me? Since c is scalar from the operation above.
is a scalar, whereas c is a vector.
I suppose my definition of x is wrong. I defined ; ; and ; . $c = 0.5*x'*P*x+q'*x$. This gives a matrix.
This is not x, but . is a vector but x is a matrix. And what you denote by c above is actually

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by