Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.?
이전 댓글 표시
The error 'Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.', is coming up for line 84. Can anyone see my issue? this is my line 84:
c(i+1) = c(i) - parError(c(i), m, g)/pardError(c(i), m, g))
i am writting an NR soultion, this is my NR soultion;
init_guess = 8;
c(1) = init_guess;
lim = 0.01;
rel_error = 1;
i = 1;
eVec = [1:20];
while ((c(i)-c(i+1))>0.01 & (i < 20))
c(i+1) = c(i) - parError(c(i), m, g)/pardError(c(i), m, g))
rel_error = abs((c(i+1)-c(i))/(c(i)))
numbers[c(i),parError(c(i), m, g)]
numbers2[pardError(c(i), m, g), c(i+1)-c(i)];
eVec(i)=rel_error;
i = i+1;
% Creates strings to be printed
str1=['At c = ', num2str(numbers2(1)), ', the error = ', num2str(numbers2(2))];
str2=['The gradient is ', num2str(numbers2(1)), ', the step is ', num2str(numbers2(2))];
disp(str);
disp(str2);
end
for the parError and pardError, these are the functions;
function error = parError( c, m, g)
error = ( (40*c) / (m*g) )-( 1-exp( (-10*c)/m ) );
end
function dError = pardError( c, m, g)
dError=(40/(m*g)) -(( 10*exp( (-10*c)/m ) )/m)
end
채택된 답변
추가 답변 (3개)
Tshiabu Angelus Dan
2023년 5월 3일
0 개 추천

댓글 수: 2
Steven Lord
2023년 5월 3일
It's easier to comment on code if you post it as text rather than an image. Please post your code as text in future questions.
Anyway, you're missing the multiplication symbols in two places. Where you have (2/Ts)(1-z) you need * between those terms, (2/Ts)*(1-z). I think if you move the cursor over one of those inner parentheses on that line the Editor will indicate one of those parentheses in each of those terms are in columns 17 and 33 as stated in the error messages.
Tshiabu Angelus Dan
2023년 5월 3일
Thank you so much Steven Lord in future, I'll post the quest as a text 🙏
Tshiabu Angelus Dan
2023년 5월 5일
import numpy as np
import matplotlib.pyplot as plt
define input signal x
x = np.sin(np.arange(0, 2*np.pi, 0.1));
calculate output signal y using digital differentiator
y = np.append*(x[0], np.diff(x))
plot input and output signals
plt.plot(x, label='input signal')
plt.plot(y, label='output signal')
plt.legend()
plt.xlabel('Sample number')
plt.ylabel('Amplitude')
plt.title('Digital Differentiator Output for a Sinusoidal Signal')
plt.show()
QUESTION1_5a
File: QUESTION1_5a.m Line: 8 Column: 16
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
QUESTION1_5a
File: QUESTION1_5a.m Line: 8 Column: 16
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
QUESTION1_5a
File: QUESTION1_5a.m Line: 8 Column: 17
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
댓글 수: 2
Steven Lord
2023년 5월 5일
The * between the name of the function (np.append) and the parentheses containing its input arguments looks suspicious.
Walter Roberson
2023년 5월 16일
import numpy as np
In MATLAB, import does not accept an as clause.
define input signal x
There is no supplied MATLAB function named define -- but it is potentially possible to define a function with the name define that accepted multiple character vectors as parameters, so this is potentially a valid MATLAB statement.
calculate output signal y using digital differentiator
Same remarks as for define
y = np.append*(x[0], np.diff(x))
In MATLAB, [] cannot appear directly after a name. [] is used for list building (but not for indexing). A constructed list would need to have an operator between any previous part of the expression and the list.
Tshiabu Angelus Dan
2023년 5월 16일
편집: Walter Roberson
2023년 5월 16일
Gp = 10^(-2/20); Gs = 10^(-12/20); wp1 = 120/(2*pi); wp2 = 300/(2*pi); ws1 = 45/(2*pi); ws2 = 450/(2*pi);
% Pre-warping Ts = 1/500; % choose highest sampling period Wp1 = tan(wp1*pi*Ts); Wp2 = tan(wp2*pi*Ts); Ws1 = tan(ws1*pi*Ts); Ws2 = tan(ws2*pi*Ts);
% Analog filter design Rp = -20*log10(Gp); Rs = -20*log10(Gs); [n, Wn] = cheb2ord([Wp1 Wp2], [Ws1 Ws2], Rp, Rs); [b, a] = cheby2(n, Rs, [Ws1 Ws2]);
% Digital filter design using bilinear transformation [bd, ad] = bilinear(b, a, 1/Ts);
% Filter the input signal using the designed filter t = 0:Ts:1; x = 1 + sin(10*pi*t) + sin(200*pi*t) + sin(400*pi*t); y = filter(bd, ad, x);
% Plot the input and output signals subplot(2,1,1) plot(t, x) title('Input Signal') xlabel('Time (s)') ylabel('Amplitude')
subplot(2,1,2) plot(t, y) title('Filtered Signal') xlabel('Time (s)') ylabel('Amplitude')
From this Design and code how can I plot the frequency response for Lowpass Chebyshev and Bandstop Chebyshev for Lowpass, Highpass Chebyshev and Bandpass Chebyshev for Highpass.
댓글 수: 1
Walter Roberson
2023년 5월 16일
This does not appear to be an explanation of why you can get the "invalid expression" message. It does not appear to fit within the context of the current discussion.
카테고리
도움말 센터 및 File Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!