hello,
I need help on anonymous function.
i need to calc array of obj [obj1, obj2, obj3] in loop each time , i call to obj with syms V and parameters value I0, IL, Rs, Rp, Vt_Ta which define before.
i try to define clussdef of obj, but get an errore.
Thanks a lot
for k=1:3
obj = @(V) I_fun(V, I0, IL, Rs, Rp, Vt_Ta) - target_value;
fplot(obj{k},[0 55],'LineWidth',2);
end

 채택된 답변

Matt J
Matt J 2023년 6월 25일
편집: Matt J 2023년 6월 25일

0 개 추천

clear obj
for k=3:-1:1
obj{k} = @(V) I_fun(V, I0, IL, Rs, Rp, Vt_Ta) - target_value;
fplot(obj{k},[0 55],'LineWidth',2);
end

댓글 수: 5

david
david 2023년 6월 25일
thanks about responde; i get this errore
"Unable to perform assignment because brace indexing is not supported for variables of this type."
for k=1:3
obj{K} = @(V) I_fun(V, I0(k), IL(k), Rs(k), Rp(k), Vt_Ta(k)) - target_value;
fplot(obj{k},[0 55],'LineWidth',2);
end
when
I0=[1.3e-10 1e-10 1e-10];
IL=[4.44 4.4 4.3];
Ns=72;
Rs=[3.6 3 2.7];
Rp=[120 130 190];
N=[0.95 0.96 0.97]
To what did you initialize the obj array prior to your loop? If you assigned an anonymous function to obj then tried to extend that array using brace indexing, that won't work. Preallocate the variable as a cell array and fill in the cells.
obj = cell(1, 5);
for k = 1:5
obj{k} = @(x) x.^k;
end
check = obj{4}(3) % 3^4 = 81
check = 81
Compare this with:
obj2 = @(x) x.^1;
for k = 2:5
obj2{k} = @(x) x.^k; % will error
end
Unable to perform assignment because brace indexing is not supported for variables of this type.
david
david 2023년 6월 25일
Thanks you,
i try it but get an errore again, here the code i try to run
V = linspace (0,50);
I0=[1.3e-10 1e-10 1e-10];
IL=[4.44 4.4 4.3];
Ns=72;
Rs=[3.6 3 2.7];
Rp=[120 130 190];
N=[0.95 0.96 0.97]
Vt_Ta = [1.7885 1.7699 1.788];
obj = cell(1,3);
for k=1:3
obj{K} = @(V) I_fun(V, I0(k), IL(k), Rs(k), Rp(k), Vt_Ta(k)) - target_value;
fplot(obj{k},[0 55],'LineWidth',2);
end
V = linspace (0,50);
I(j) = zeros(size(V));
for j=1:6;
% Newton Raphson Method
I = I- (IL- I- I0.*( exp((V+I.*Rs)./Vt_Ta) -1)-(V+I.*Rs)/Rp)./ (-1 - I0.*(Rs/Vt_Ta)*exp((V+I.*Rs)./Vt_Ta)-Rs/Rp);
end
Paul
Paul 2023년 6월 25일
did the error arise because the for loop index variable is k (lower case) , but the index variable into the obj cell array is K (upper case)?
david
david 2023년 6월 26일
Thank, i see it later.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Performance and Memory에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2023년 6월 25일

댓글:

2023년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by