Does anyone know what wrong with my code? The other value should be 3.565 and not 1.7826.

4 个评论

Unfortunately my version of MATLAB is not available to execute *pictures* of code.
clear;
clc;
Ns=23;
Np=18;
Nr=59;
omega_c=1;
omega_r=0;
syms omega_p omega_s
omega_p-(Nr/Np)*omega_r== omega_c *( 1- (Nr/Np));
omega_s-omega_c * ( 1+ (Np/Ns))==-(Np/Ns)*omega_p ;
A= [1 -(Nr/Np)*omega_r; 1 (Np/Ns)*omega_p]
b= [ omega_c*(1- (Nr/Np)); omega_c*( 1+(Np/Ns))]
X= linsolve(A,b);
clear;
clc;
Ns=23;
Np=18;
Nr=59;
omega_c=1;
omega_r=0;
syms omega_p omega_s
omega_p-(Nr/Np)*omega_r== omega_c *( 1- (Nr/Np));
omega_s-omega_c * ( 1+ (Np/Ns))==-(Np/Ns)*omega_p ;
A= [1 -(Nr/Np)*omega_r; 1 (Np/Ns)*omega_p]
A = 
b= [ omega_c*(1- (Nr/Np)); 2*omega_c*( 1+(Np/Ns))]
b = 2×1
-2.2778 3.5652
X= linsolve(A,b)
X = 
The online version is showing the right output. What version you are using?
I meant this code.
When I solve the equations by hand. omega_s is quals to 3.5652, but now it shows it is equal to 1.7826
clear;
clc;
Ns=23;
Np=18;
Nr=59;
omega_c=1;
omega_r=0;
syms omega_p omega_s
omega_p-(Nr/Np)*omega_r== omega_c *( 1- (Nr/Np));
omega_s+(Np/Ns)*omega_p== omega_c * ( 1+ (Np/Ns)) ;
A= [1 -(Nr/Np)*omega_r; 1 (Np/Ns)*omega_p]
A = 
b= [ omega_c*(1- (Nr/Np)); omega_c*( 1+(Np/Ns))]
b = 2×1
-2.2778 1.7826
X= linsolve(A,b);

请先登录,再进行评论。

回答(2 个)

omega_p-(Nr/Np)*omega_r== omega_c *( 1- (Nr/Np));
omega_s-omega_c * ( 1+ (Np/Ns))==-(Np/Ns)*omega_p ;
Those statements construct symbolic equalities and then throw them away. You do not have any assignment statements there and you do not have solve()

1 个评论

So, what should I do to ask matlab to solve these two equations to find omega_p and omega_s?

请先登录,再进行评论。

I take it that the A and B variables are your attempts to convert the first two equations into the coefficient matrix and right-hand side of a system of linear equations? omega_c and omega_r are constants.
omega_p-(Nr/Np)*omega_r== omega_c *( 1- (Nr/Np));
omega_s-omega_c * ( 1+ (Np/Ns))==-(Np/Ns)*omega_p ;
A= [1 -(Nr/Np)*omega_r; 1 (Np/Ns)*omega_p]
b= [ omega_c*(1- (Nr/Np)); omega_c*( 1+(Np/Ns))]
You've performed the conversion incorrectly. Let's rewrite your equations with the constant terms all on the right side of the equals sign.
omega_p== omega_c *( 1- (Nr/Np)) + (Nr/Np)*omega_r;
(Np/Ns)*omega_p + omega_s== omega_c * ( 1+ (Np/Ns));
If we assume you're solving for x = [omega_p; omega_s] then you can see that the first row of A is obviously incorrect. omega_s does not appear in the first equation so its coefficient (the (1, 2) element in A) must be 0. In this case you luck out since omega_r is 0 but I'd still fix the first rows of A and b so that later if you try to solve this same problem for omega_r not equal to 0 it solves the problem correctly.
Your second row of A is in the reverse order and should not include omega_p explicitly.

类别

帮助中心File Exchange 中查找有关 Matrices and Arrays 的更多信息

产品

版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by