How to define variable (for later use) that contains another defined variables

Simple question
I.e I have variable N=Np/Ns. I;ve defined values for Np and Ns (which I may want to change later) but for my latter euqations I want to put simply only N, insteed of typing Np/Ns. How to define N in that way when I pun N in some equation it will pass Np/Ns.
I've tried simply N = 'Np/Ns' , but when I checked it by typing F = N + 1, insteed of simply calculate F = Np/Ns + 1, the output is strange 8 element matix.

1 comentario

"the output is strange 8 element matix"
Not very strange: you created a character vector and then added one to every character code:
1+'Np/Ns'
ans = 1×5
79 113 48 79 116
If you want to perform numeric/symbolic operations, character vectors are unlikely to be the solution.

Iniciar sesión para comentar.

Respuestas (1)

np=5;ns=3;
n=@(np,ns)np/ns;
f=n(np,ns)+1;
np=8;ns=5;
f=n(np,ns)^2+3;

6 comentarios

Marcin Fisior
Marcin Fisior el 19 de Mayo de 2022
Editada: Marcin Fisior el 19 de Mayo de 2022
Thanks but I dont want to type everywhere n(np,ns). since I need to use it in vary large equations (where N is only one of many of similar variables) so this method will be prone to errors. Is there possibility to to type only "N" ? (should be since Np/Ns is already assigned with values to N)
and the first equation when I have to put N are those 2 (later the quations are making more complicated since they are nested)
where Vcr
What variables are given ? What variables are unknown ? What is the final task of your computations ?
Marcin Fisior
Marcin Fisior el 19 de Mayo de 2022
Editada: Marcin Fisior el 19 de Mayo de 2022
Torsten starting from page 5. IV. DESIGN ALGORITHM DERIVATION (PN MODE)
Np,Ns, Vi,min, fs,min are given, Cr is iterated to get Lr, Lp and wr
https://www.ece.queensu.ca/people/Y-F-Liu/Pub/Papers/2016/2016_TPEL_Zhiyuan_An%20Accurate%20Design%20Algorithm%20for%20LLC%20Resonant%20Converters-Part%20I.pdf
Why not just write a function? That seems like the obvious approach.
Torsten
Torsten el 19 de Mayo de 2022
Editada: Torsten el 19 de Mayo de 2022
As Stephen says, put all your computations - one after the other - in a function. Then you don't need to combine function handles, but you can simply work with variables.
Yeah, now I see that will be best approach. Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Versión

R2020b

Etiquetas

Preguntada:

el 19 de Mayo de 2022

Comentada:

el 19 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by