I get wrong value

1 view (last 30 days)
Asama Younis Said Mohsin Al Quwaitai
Answered: Steven Lord on 26 Oct 2021
Does anyone know what wrong with my code? The other value should be 3.565 and not 1.7826.
  4 Comments
Asama Younis Said Mohsin Al Quwaitai
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);

Sign in to comment.

Answers (2)

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

Sign in to comment.


Steven Lord
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.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!