Why won't this run? Getting an mldivide error.....

1 回表示 (過去 30 日間)
Omar
Omar 2011 年 9 月 28 日
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

採用された回答

UJJWAL
UJJWAL 2011 年 9 月 28 日
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 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by