![Plotting the values of a vector - 2019 11 26.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/250473/Plotting%20the%20values%20of%20a%20vector%20-%202019%2011%2026.png)
Plotting the values of a vector
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Anna Mogilevskaja
le 26 Nov 2019
Commenté : Star Strider
le 27 Nov 2019
Hi,
this is the code I wrote:
A=[1 1.1; 1.1 1]
l= [sym(2)/sym(3); sym(1)/sym(3)]
w=1
B=[1.09 1.44; 1.44 0.99]
r=linspace(0,1,100)
for r=0:0.01:1
p=w*(inv(B-(1+r)*A))*l
end
I would like to plot both values of the vector p on a graph to show the development of prices when r changes. Unfortunately, I could not find the right code yet. Does anyone have an idea?
Greetings Anna
0 commentaires
Réponse acceptée
Star Strider
le 26 Nov 2019
Modifié(e) : Star Strider
le 26 Nov 2019
Try this:
A=[1 1.1; 1.1 1];
l = [2; 1]/3;
B=[1.09 1.44; 1.44 0.99];
w=1;
r=linspace(0,1,100);
for k = 1:numel(r)
p(:,k) = w*((B-(1+r(k))*A))\l;
end
figure
plot(r, p)
grid
xlabel('r')
ylabel('p(r)')
I replaced your inv call with the mldivide,\ operator, and eliminated the symbolic code, since it is not necessary.
EDIT —
Added plot figure —
![Plotting the values of a vector - 2019 11 26.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/250473/Plotting%20the%20values%20of%20a%20vector%20-%202019%2011%2026.png)
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Title dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!