I get wrong value
4 views (last 30 days)
Show older comments
Does anyone know what wrong with my code? The other value should be 3.565 and not 1.7826.
4 Comments
KSSV
on 26 Oct 2021
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)); 2*omega_c*( 1+(Np/Ns))]
X= linsolve(A,b)
The online version is showing the right output. What version you are using?
Asama Younis Said Mohsin Al Quwaitai
on 26 Oct 2021
Edited: Asama Younis Said Mohsin Al Quwaitai
on 26 Oct 2021
Answers (2)
Walter Roberson
on 26 Oct 2021
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()
Steven Lord
on 26 Oct 2021
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!