I get wrong value

16 visualizaciones (últimos 30 días)
Asama Younis Said Mohsin Al Quwaitai
Asama Younis Said Mohsin Al Quwaitai el 26 de Oct. de 2021
Respondida: Steven Lord el 26 de Oct. de 2021
Does anyone know what wrong with my code? The other value should be 3.565 and not 1.7826.
  4 comentarios
KSSV
KSSV el 26 de Oct. de 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]
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?
Asama Younis Said Mohsin Al Quwaitai
Asama Younis Said Mohsin Al Quwaitai el 26 de Oct. de 2021
Editada: Asama Younis Said Mohsin Al Quwaitai el 26 de Oct. de 2021
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);

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 26 de Oct. de 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()
  1 comentario
Asama Younis Said Mohsin Al Quwaitai
Asama Younis Said Mohsin Al Quwaitai el 26 de Oct. de 2021
So, what should I do to ask matlab to solve these two equations to find omega_p and omega_s?

Iniciar sesión para comentar.


Steven Lord
Steven Lord el 26 de Oct. de 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.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by