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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by