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]
Steven Lord
Steven Lord 2023 年 6 月 25 日
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 ExchangePerformance 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