How do I solve this matrix in a loop for different values for P?

x1= [-0.005:0.005]
x2= [-0.005:0.005]
x3= [-0.005:0.005]
x4= [-0.005:0.005]
x5= [-0.005:0.005]
w1= [-0.005:0.005]
w2= [-0.005:0.005]
w3= [-0.005:0.005]
w4= [-0.005:0.005]
w5= [-0.005:0.005]
P=[0 x1 w1
0 x2 w2
0 x3 w3
0 x4 w4
0 x5 w5]
A=[1.0000 0.005 0.02
1.0000 0.014 0.17
1.0000 0.022 0.42
1.0000 0.036 1.16
1.0000 0.052 2.44]
Y= A+P
B=[0.86
0.76
0.74
0.57
0.39]
aa=Y\B

4 commentaires

What exactly is your question? Which different values for P would you want to have? Your code already runs.
x1= [-0.005:0.005];
x2= [-0.005:0.005];
x3= [-0.005:0.005];
x4= [-0.005:0.005];
x5= [-0.005:0.005];
w1= [-0.005:0.005];
w2= [-0.005:0.005];
w3= [-0.005:0.005];
w4= [-0.005:0.005];
w5= [-0.005:0.005];
P=[0 x1 w1
0 x2 w2
0 x3 w3
0 x4 w4
0 x5 w5];
A=[1.0000 0.005 0.02
1.0000 0.014 0.17
1.0000 0.022 0.42
1.0000 0.036 1.16
1.0000 0.052 2.44];
Y= A+P;
B=[0.86
0.76
0.74
0.57
0.39];
aa=Y\B
aa = 3×1
0.8534 -6.4035 -0.0672
The question is not clear. Simply run the same code with the different values of P.
Some hints:
[] is Matlab's operator for the concatenation of arrays. With [-0.005:0.005] you contcate the vector -0.005:0.005 with nothing, therefore the square brackets are a waste of time only.
Thanks for the reply. How could I define P so that it takes different values of x1,x2... w1,w2?
I want to run this code for error analysis by slightly changing the Values of A with the help of Matrix P. I am having trouble choosing a random set of values of P and collecting different set of values

Connectez-vous pour commenter.

 Réponse acceptée

I'm guessing you want a for loop like this:
x1= linspace(-0.005,0.005,10);
x2= linspace(-0.005,0.005,10);
x3= linspace(-0.005,0.005,10);
x4= linspace(-0.005,0.005,10);
x5= linspace(-0.005,0.005,10);
w1= linspace(-0.005,0.005,10);
w2= linspace(-0.005,0.005,10);
w3= linspace(-0.005,0.005,10);
w4= linspace(-0.005,0.005,10);
w5= linspace(-0.005,0.005,10);
A=[1.0000 0.005 0.02
1.0000 0.014 0.17
1.0000 0.022 0.42
1.0000 0.036 1.16
1.0000 0.052 2.44];
B=[0.86
0.76
0.74
0.57
0.39];
aa=zeros(size(A,2),numel(x1));
for n=1:numel(x1)
P=[0 x1(n) w1(n)
0 x2(n) w2(n)
0 x3(n) w3(n)
0 x4(n) w4(n)
0 x5(n) w5(n)];
Y= A+P;
aa(:,n)=Y\B;
end
aa
aa = 3×10
0.8534 0.8606 0.8678 0.8750 0.8822 0.8894 0.8966 0.9038 0.9109 0.9181 -6.4035 -6.4035 -6.4035 -6.4035 -6.4035 -6.4035 -6.4035 -6.4035 -6.4035 -6.4035 -0.0672 -0.0672 -0.0672 -0.0672 -0.0672 -0.0672 -0.0672 -0.0672 -0.0672 -0.0672

Plus de réponses (0)

Catégories

Produits

Version

R2020b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by