Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What\'s wrong with my SCILAB code? I am a beginner to SCILAB, but my intuitive u

ID: 1846051 • Letter: W

Question

What's wrong with my SCILAB code? I am a beginner to SCILAB, but my intuitive understanding of the error tells me that it thinks there is something wrong with my use of the subtraction operator.


==============================================================================================

-->Z = 75; R = 225; C = 0.6D-6; L = 0.5;

-->function [z] = f(w)

-->z1 = 1/(R^2); z2 = w*C; z3 = 1/(w*L);

-->z = (1/(z1+(z2-z3)^2)^0.5)-Z;

-->endfunction;

-->w=[-25D+3:500:25D+3]; z = f(w); plot(w,z); xgrid(5); xlabel("w"); ylabel("z");

!--error 9

Inconsistent subtraction.

at line       3 of function f called by :  

w=[-25D+3:500:25D+3]; z = f(w); plot(w,z); xgrid(5); xlabel("w"); ylabel("z");

==============================================================================================

Explanation / Answer

The error is occuring when you are using the function z=f(w)

this is because the parameter z1 has only one element whereas z2 and z3 are column vectors of length 101. Scilab performs all opertions considering variables as matrices. That is the reason you are getting an inconsistent subtraction error. To remove the error you can use a for loop in the function defination.

I am attaching a sample code for the same.


Comment if you have any further doubts..



-->Z = 75; R = 225; C = 0.6D-6; L = 0.5;

-->

-->function [z] = f(w)

-->z1 = 1/(R^2); z2 = w*C; z3 = 1/(w*L);

-->a = length(w);

-->for i=1:a

-->z(i) = (1/(z1+(z2(i)-z3(i))^2)^0.5)-Z;

-->end

-->endfunction;

-->

-->w=[(-25)*1D+3:500:25D+3]; z = f(w); plot(w,z); xgrid(5); xlabel("w"); ylabel("z");

-->

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote