how do i change the params value continuously by using the for loop in the function:

7 Ansichten (letzte 30 Tage)
Hii,
i have one function inside which i created the variables name params. now im using that function in another file2,3,4 but now i want a result "I1c" from file_4 for different values of 'm' and for same values of "n" in file_1. actually i was thinking to apply "for loop" in file 4 for changing "m" but is not doing so

file 1

function params = params( )
%UNTITLED Summary of this function goes here
n=5;
m=2;
params.n=n;
params.m=m;
params.mu1c = -(1./2).*n-(1./2).*m+3./2 ;
params.nu1c = (1./2).*n+(1./2).*m+1./2 ;
end
FILE2
function [Lommel_S2_conj]= temp()
p=params();
n=p.n;
m=p.m;
mu1c = p.mu1c;
nu1c = p.nu1c;
Lommel_S2_conj =@(omega) conj(meijerG([(1./2).*mu1c+1./2], [], [(1./2).*mu1c+1./2, (1./2).*nu1c, -(1./2).*nu1c], [], -(1./4).*omega.^2).*2^mu1c./(2.*gamma(-(1./2).*mu1c+(1./2).*nu1c+1./2).*gamma(-(1./2).*mu1c-(1./2).*nu1c+1./2)));
end
FILE3
function [Lommel_S2]= temp()
p=params();
n=p.n;
m=p.m;
mu1c = p.mu1c;
nu1c = p.nu1c;
Lommel_S2 =@(omega) meijerG([(1./2).*mu1c+1./2], [], [(1./2).*mu1c+1./2, (1./2).*nu1c, -(1./2).*nu1c], [], -(1./4).*omega.^2).*2^mu1c./(2.*gamma(-(1./2).*mu1c+(1./2).*nu1c+1./2).*gamma(-(1./2).*mu1c-(1./2).*nu1c+1./2));
end
FILE4
clc
clear all
p=params();
n=p.n;
m=p.m;
mu1c = p.mu1c;
nu1c = p.nu1c;
Lommel_1c=Lommel_Ic1();
Lommel_conj_1c=L_conj_Ic1();
I1c =@(omega) (-i.*sqrt(2).*((1+i).*(-1).^(-(1./4).*n-(1./4).*m).* Lommel_conj_1c( omega)+((-1)+i).* Lommel_1c(omega).*(-1).^((1./4).*n+(1./4).*m)).*omega.^((1./2).*n+(1./2).*m+1./2)).*(1./(2.*m+2.*n));
f1=1;
f2 = cos(alpha);
if n==0
f3=f1
elseif n==1
f3=f2;
else
for k=3:1:n+1;
f3=expand(2*f2*cos(alpha)-f1);
f1=f2;
f2=f3;
end
end
f3;
c = coeffs(f3,cos(alpha),'All');
for m= 0:1:n;
h =h+c(n+1-m)*eval(I1c(omega));
end
eval(h)
please help me...Thank you!!!!!!!

Antworten (1)

Sourabh Kondapaka
Sourabh Kondapaka am 17 Feb. 2021
Bearbeitet: Sourabh Kondapaka am 18 Feb. 2021
I have modified your file1.m, for the function to take input arguements. Because of this you'll need to change how you are calling the "params" function. ie by passing the default values.
%Instead of calling params this way:
p = params();
%Call it this way:
p = params(2,5)
So, your file2.m, file3.m and file4.m will require changes as above.
Your file1.m now looks like this:
function out = params(m,n)
out.n=n;
out.m=m;
out.mu1c = -(1./2).*n-(1./2).*m+3./2 ;
out.nu1c = (1./2).*n+(1./2).*m+1./2 ;
end
Now because of the change made in file1.m, it will help you in acheiving what you want in file4.m by just passing the input arguements ie different values of 'm' and for same values of "n"
% This is an example of the part of code that will look different for calling with
% different values of 'm' and same values of 'n'
for i=1:10
% You are calling the params function with same value of n and different value of m
p = params(i, 5);
% Your code goes here
end
If you want to learn more about default values for input arguments for a matlab function, please check out
I would suggest you to take the free Matlab OnRamp course which will bring you up to speed with the Matlab language.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by