Why won't this run? Getting an mldivide error.....
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need to graph the equation p for varying g values in polar coordinates I assume from 0 to 2pi radians. Here is my code, i know it isnt the best way to go about coding it but i wanted somethign simple
g=0;
ga=0.1;
gb=0.5;
gc=0.9;
gd=0.99;
x=[0:0.1:2*pi];
p=(1/4*pi)*((1-g^2)/((1+g^2-2*g*cos(x))^1.5));
p1=(1/4*pi)*((1-ga^2)/((1+ga^2-2*ga*cos(x))^1.5));
p2=(1/4*pi)*((1-gb^2)/((1+gb^2-2*gb*cos(x))^1.5));
p3=(1/4*pi)*((1-gc^2)/((1+gc^2-2*gc*cos(x))^1.5));
p4=(1/4*pi)*((1-gd^2)/((1+gd^2-2*gd*cos(x))^1.5));
polar(p,'bo');
hold on
polar(x,p1,'go');
hold on
polar(x,p2,'co');
hold on
polar(x,p3,'ro');
hold on
polar(x,p4,'yo');
hold on
0 commentaires
Réponse acceptée
UJJWAL
le 28 Sep 2011
Following is your code which I have modified :-
clc;
clear all;
g=0;
ga=0.1;
gb=0.5;
gc=0.9;
gd=0.99; x=0:0.1:2*pi;
p=(1/4*pi)*((1-g^2)*((1+g^2-2*g*cos(x)).^-1.5));
p1=(1/4*pi)*((1-ga^2)*((1+ga^2-2*ga*cos(x)).^-1.5));
p2=(1/4*pi)*((1-gb^2)*((1+gb^2-2*gb*cos(x)).^-1.5));
p3=(1/4*pi)*((1-gc^2)*((1+gc^2-2*gc*cos(x)).^-1.5));
p4=(1/4*pi)*((1-gd^2)*((1+gd^2-2*gd*cos(x)).^-1.5));
polar(p,'bo'); hold on
polar(x,p1,'go'); hold on
polar(x,p2,'co'); hold on
polar(x,p3,'ro'); hold on
polar(x,p4,'yo'); hold on
There were certain errors :-
a) Division by a vector is not allowed. So multiply with those vectors raised to the corresponding negetive powers as u can see in the above code.
b) Elementwise multiplication is performed by using .* and elementwise division is performed by using ./ So cos(x)^1.5 would refer to the matrix power which is a different concept while here you need elementwise power so you will use .^
I hope it is helpful. For more details refer to the documentation.
HAPPY TO HELP
UJJWAL
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations 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!